Maven deploy secondary file to repository

2019-07-04 12:01发布

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)?

1条回答
beautiful°
2楼-- · 2019-07-04 12:12

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.

查看更多
登录 后发表回答