To meet the provided requirements, two configuration steps are then required:
- Disable the default artifact installation to the local repository, via the
skip
option of the Maven Install Plugin
- Configure the
install-file
goal within the POM in order to have it as part of your build (hence no need to invoke it manually from command line)
The following configuration would provide it:
<properties>
<library.repository.folder>../libs</library.repository.folder>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-install-plugin</artifactId>
<version>2.5.2</version>
<configuration>
<skip>true</skip>
</configuration>
<executions>
<execution>
<id>install-artifact</id>
<phase>install</phase>
<goals>
<goal>install-file</goal>
</goals>
<configuration>
<groupId>${project.groupId}</groupId>
<artifactId>${project.artifactId}</artifactId>
<version>${project.version}</version>
<packaging>${project.packaging}</packaging>
<file>${project.build.directory}/${project.build.finalName}.${project.packaging}</file>
<localRepositoryPath>${library.repository.folder}</localRepositoryPath>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
Please note the library.repository.folder
property used to point to the desired target lib
folder (to change in case of different path). The configuration provided above makes use of standard maven properties (for project coordinates and packaging), but you can change them (or hard-code real values) as required.
Also note that the install-file
goal will recreate under the lib
folder the same folders structure as in the local repository (lib\groupId\artifactId\version\file.jar). If you instead would like to have the file straight under the lib folder (lib\file.jar) you could then move to the following configuration:
<properties>
<library.repository.folder>../libs</library.repository.folder>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-install-plugin</artifactId>
<version>2.5.2</version>
<configuration>
<skip>true</skip>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.6</version>
<configuration>
<outputDirectory>${library.repository.folder}</outputDirectory>
</configuration>
</plugin>
</plugins>
</build>
This time we are not using the install-file
goal but rather the jar
goal of the Maven Jar Plugin to place the packaged artifact directly to the lib
folder (instead of the standard target
folder) and during the package phase
(not install
).
If by any reason you want to keep the final artifact in the target folder AND have it straight copied to the lib folder (no maven folders hierarchy) AND during the install phase, then you could move to the following configuration:
<properties>
<library.repository.folder>../libs</library.repository.folder>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-install-plugin</artifactId>
<version>2.5.2</version>
<configuration>
<skip>true</skip>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.6</version>
<executions>
<execution>
<id>re-package-into-lib</id>
<phase>install</phase>
<goals>
<goal>jar</goal>
</goals>
<configuration>
<outputDirectory>${library.repository.folder}</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>