1

I tried using this plugin to move jarfiles from maven's target to an external dir after the build:

  <plugin>
    <artifactId>maven-resources-plugin</artifactId>
    <version>3.0.2</version>
    <executions>
      <execution>
        <id>copy-files-on-build</id>
        <phase>validate</phase>
        <goals>
          <goal>copy-resources</goal>
        </goals>
        <configuration>
          <outputDirectory>${basedir}/../jarfiles</outputDirectory>
          <resources>
            <resource>
              <directory>${build.directory}</directory>
              <include>*.jar</include>
              <filtering>false</filtering>
            </resource>
          </resources>
        </configuration>
      </execution>
    </executions>
  </plugin>

But it only works from the second build onwards, it doesn't copy anything over on the first build.

I tried changing <phase> to all of install, deploy, post-install, post-deploy, etc., but never got the files to copy across on the first mvn install in that project (i.e. ./target dir has not been created yet.)

How do I make sure the jars are copied every build (and that they are the most up-to-date, reflecting the current source.)

theonlygusti
  • 11,032
  • 11
  • 64
  • 119

2 Answers2

0

I would have tried it the same way as you did ... but maybe the resources plugin expands its "include" way before it is actually applied (which would be shame). But I don't know, I would try to track it down in the logs.

If you cannot make this work, you can still use the good old Ant copy targets through the maven antrun plugin

https://stackoverflow.com/a/694175/927493

J Fabian Meier
  • 33,516
  • 10
  • 64
  • 142
0

At first I tried using this:

  <plugin>
    <!-- copy jarfiles straight to ../server/plugins so we can test
         the plugin without having to move them ourselves -->
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-jar-plugin</artifactId>
    <version>2.3.1</version>
    <configuration>
      <outputDirectory>${basedir}/../server/plugins</outputDirectory>
    </configuration>
  </plugin>

But it didn't work for jar-with-dependencies.

So now I use this:

<plugin>
  <groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-antrun-plugin</artifactId>
  <version>1.8</version>
  <executions>
    <execution>
      <phase>install</phase>
      <configuration>
        <target>
          <copy file="${project.build.directory}/${project.artifactId}-${project.version}.jar" todir="${project.basedir}/../jarfiles" />
        </target>
      </configuration>
      <goals>
        <goal>run</goal>
      </goals>
    </execution>
  </executions>
</plugin>
theonlygusti
  • 11,032
  • 11
  • 64
  • 119