简体   繁体   中英

Maven Deployment Parameters in pom.xml

I have a Maven project which should deploy their compiled files in another folder. Currently, i am doing this by specifying the parameter 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? 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. Both are different Github projects and therefore in different folders. I configured Maven so that the target files are deployed in the repo folder. 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!

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 Deploy means deploying the artifact to remote repository. Remote repository is where Maven search for artifacts and download to local repository. It is seldom "another folder". We normally use <distributionManagement> to configure the remote repository to deploy. Normally we used altDeploymentRepository to deploy to a different remote repo as configured in 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.

Apologies up-front that this is *nix based (see 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:

<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:

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>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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