简体   繁体   English

pom.xml中的Maven部署参数

[英]Maven Deployment Parameters in pom.xml

I have a Maven project which should deploy their compiled files in another folder. 我有一个Maven项目,应该将他们编译的文件部署在另一个文件夹中。 Currently, i am doing this by specifying the parameter altDeploymentRepository : 目前,我通过指定参数altDeploymentRepository来做到这altDeploymentRepository

mvn -DaltDeploymentRepository=snapshot-repo::default::file:/home/user/some/folder/mvn-repo/snapshots deploy

My question: Is it possible to do a simple mvn deploy instead and move the parameter declaration to the pom.xml instead? 我的问题:是否可以改为执行简单的mvn deploy并将参数声明移到pom.xml中? If yes, how? 如果有,怎么样?

Update 更新

I get asked why i want to do this. 我被问到为什么要这样做。 I have separated my project into the Maven project with the sources and the Maven repository. 我已将我的项目与源和Maven存储库分离到Maven项目中。 Both are different Github projects and therefore in different folders. 两者都是不同的Github项目,因此在不同的文件夹中。 I configured Maven so that the target files are deployed in the repo folder. 我配置了Maven,以便将目标文件部署在repo文件夹中。 After that i just need to git add, commit and push the changes. 之后我只需要添加,提交并推送更改。

If there is any way to push the target files directly to the desired Github repo with maven deploy or to make this procedure more straightforward, i am all ears! 如果有任何方法可以将目标文件直接推送到具有maven deploy的所需Github存储库,或者为了使这个过程更加直接,我全都耳朵!

Just to make sure you actually understand the meaning of "deploy" in Maven, coz it is quite weird to "deploy to other folder" as what you are doing. 只是为了确保你真正理解Maven中“部署”的含义,因为你正在做的事情“部署到其他文件夹”是很奇怪的。

Maven Deploy means deploying the artifact to remote repository. Maven Deploy意味着将工件部署到远程存储库。 Remote repository is where Maven search for artifacts and download to local repository. 远程存储库是Maven搜索工件并下载到本地存储库的地方。 It is seldom "another folder". 它很少是“另一个文件夹”。 We normally use <distributionManagement> to configure the remote repository to deploy. 我们通常使用<distributionManagement>来配置要部署的远程存储库。 Normally we used altDeploymentRepository to deploy to a different remote repo as configured in distrubutionManagement . 通常我们使用altDeploymentRepository作为配置部署到不同的远程回购distrubutionManagement

If you simply want to put your built artifact to a separate folder, which is not aimed for a "remote repository", I believe assembly (or similar plugin) is what you need. 如果您只是想将构建的工件放到一个单独的文件夹中,而不是针对“远程存储库”,我相信汇编(或类似的插件)就是您所需要的。

Similar to the above answer, it is possible to isolate builds from deployments by initially deploying to a file system repo under the target folder as part of your build, then using the wagon plugin to sync up your local (and private) staging-repository to a more public repository. 与上面的答案类似,可以通过最初部署到目标文件夹下的文件系统仓库作为构建的一部分来隔离部署中的构建,然后使用wagon插件将本地(和私有)staging-repository同步到一个更公共的存储库。

Apologies up-front that this is *nix based (see pwd ) 道歉,这是基于* nix的(参见pwd

mvn -DaltDeploymentRepository=local-staged-repo::default::file://`pwd`/target/staged-repo \
    clean \
    deploy

Alternatively, it can be coded inside your pom.xml like so: 或者,它可以在你的pom.xml中编码,如下所示:

<pluginManagement>
  <plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-deploy-plugin</artifactId>
    <version>2.7</version>
    <configuration>
      <altDeploymentRepository>
        staged-repo::default::file:${project.basedir}/target/staged-repo
      </altDeploymentRepository>
    </configuration>
  </plugin>
</pluginManagement>
    ...

Then at a later stage, run from your project's root folder. 然后在稍后阶段,从项目的根文件夹运行。 You can merge your staged-repo inside the target folder of your root pom.xml to a more permanent repository using the following plugin: 您可以使用以下插件将root pom.xml的目标文件夹中的staged-repo合并到更永久的存储库:

mvn org.codehaus.mojo:wagon-maven-plugin:1.0-beta-5:merge-maven-repos \
  -Dwagon.source=file://`pwd`/target/staged-repo \ 
  -Dwagon.target=http://<some-repo>/release \
  -Djava.io.tmpdir=/tmp 

Ok, that was easier than expected. 好的,这比预期的要容易。 I needed to add a configuration block to my plugin: 我需要在我的插件中添加一个配置块:

        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-deploy-plugin</artifactId>
            <version>2.7</version>
            <configuration>
                <altDeploymentRepository>
                  snapshot-repo::default::file:/home/user/some/folder/mvn-repo/snapshots
                </altDeploymentRepository>
            </configuration>
            <dependencies>
                <dependency>
                    <groupId>com.google.code.maven-svn-wagon</groupId>
                    <artifactId>maven-svn-wagon</artifactId>
                    <version>1.4</version>
                </dependency>
            </dependencies>
        </plugin>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM