简体   繁体   中英

Maven deploy secondary file to repository

I'm looking to deploy alongside my jars, wars, etc. an XML file. I can do this manually with a classifier:

mvn deploy:deploy-file -DgroupId=${GROUP_ID} \
-DartifactId=$ARTIFACT_ID \
-Dversion=$VERSION \
-Dpackaging=xml \
-Dclassifier=metadata \
-Dfile=metadata.xml \
-DrepositoryId=releases \
-Durl=http://localhost/nexus/content/repositories/releases \
-DgeneratePom=false

I'd like to have the xml file populated from properties in the pom.xml and have it deployed alongside the main artifact in one simple command, something to apply to all our internal projects.

Is it possible to configure the deploy plugin to do this (and how)? Or do I need to go down some other route (custom maven plugin perhaps)?

The best solution for such purposes is simply using the build-helper-maven-plugin like this:

  <plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>build-helper-maven-plugin</artifactId>
    <version>1.8</version>
    <executions>
      <execution>
        <id>attach-artifacts</id>
        <phase>package</phase>
        <goals>
          <goal>attach-artifact</goal>
        </goals>
        <configuration>
          <artifacts>
            <artifact>
              <file>x1.xml</file>
              <type>xml</type>
              <classifier>optional</classifier>
            </artifact>
            ...
          </artifacts>
        </configuration>
      </execution>
    </executions>
  </plugin>

With such kind of setup you can use the usual mvn deploy which will also deploy the additional artifacts which you can attach to your usual build artifacts.

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