I have a third-party bank, which is necessary for our project. It is not available in the maven central repository, so I used maven-install-plugin to install the jar locally during build. I linked the install-file target to the validate phase and this basically works. Below you will find a fragment of the pom.xml file:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> <modelVersion>4.0.0</modelVersion> ... <build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-install-plugin</artifactId> <version>2.3</version> <executions> <execution> <id>install-myartifact</id> <phase>validate</phase> <goals> <goal>install-file</goal> </goals> <configuration> <file>${basedir}/lib/myartifact-1.2.3.jar</file> <groupId>com.example</groupId> <artifactId>myartifact</artifactId> <version>1.2.3</version> <packaging>jar</packaging> <generatePom>true</generatePom> </configuration> </execution> </executions> </plugin> </plugins> </build> <dependencies> <dependency> <groupId>com.example</groupId> <artifactId>myartifact</artifactId> <version>1.2.3</version> </dependency> </dependencies>
However, there is a catch. Most of our developers and our Jenkins installation run "mvn clean install". The “verify” phase is not part of the “clean” life cycle, and the clean phase inexplicably requires all the dependencies to run. Therefore, the first time someone starts this assembly, it does not work.
[INFO] Scanning for projects... [INFO] ------------------------------------------------------------------------ [INFO] Building MyModule [INFO] task-segment: [clean, install] [INFO] ------------------------------------------------------------------------ [INFO] [clean:clean] [INFO] Deleting directory C:\svn\trunk\mymodule\target Downloading: http://nexusserver.local:8080/nexus/content/groups/public/com/example/myartifact-1.2.3.pom [INFO] Unable to find resource 'com.example:myartifact:pom:1.2.3' in repository central (http://central) [INFO] ------------------------------------------------------------------------ [ERROR] BUILD ERROR [INFO] ------------------------------------------------------------------------ [INFO] Failed to resolve artifact. Missing: ---------- 1) com.example:myartifact:jar:1.2.3 Try downloading the file manually from the project website. Then, install it using the command: mvn install:install-file -DgroupId=com.example -DartifactId=myartifact -Dversion=1.2.3 -Dpackaging=jar -Dfile=/path/to/file Alternatively, if you host your own repository you can deploy the file there: mvn deploy:deploy-file -DgroupId=com.example -DartifactId=myartifact -Dversion=1.2.3 -Dpackaging=jar -Dfile=/path/to/file -Durl=[url] -DrepositoryId=[id] Path to dependency: 1) com.example:mymodule:war:0.0.1-SNAPSHOT 2) com.example:myartifact:jar:1.2.3 ---------- 1 required artifact is missing. for artifact: com.example:mymodule:war:0.0.1-SNAPSHOT from the specified remote repositories: nexus (http://nexusserver.local:8080/nexus/content/groups/public) [INFO] ------------------------------------------------------------------------ [INFO] For more information, run Maven with the -e switch [INFO] ------------------------------------------------------------------------ [INFO] Total time: 1 second [INFO] Finished at: Thu Jun 09 11:01:24 EDT 2011 [INFO] Final Memory: 17M/247M [INFO] ------------------------------------------------------------------------
If I just ran "mvn install", the jar was installed during the "check", and I can run "mvn clean install" in subsequent builds. However, our build server does not have this flexibility. I reviewed the following:
- Moving the phase to “pre-clean”, but it is assumed that everyone always uses the clean-up for the first time. This would not help if someone just “installed mvn”.
- Copying of the performance, one of which occurs during the "preliminary cleaning" and one occurs during the "check". This covers all bases, but the copied code leaves a bad taste.
Ideally, I would like another option. Is it possible to work without any dependencies? Or run the plugin twice without a full copy of the execution? Thanks!
source share