java - Install local jar dependency as part of the lifecycle, before Maven attempts to resolve it -
java - Install local jar dependency as part of the lifecycle, before Maven attempts to resolve it -
because of incompatibilities between 2 dependencies, forced create shaded version of 1 of dependencies. means project depends on local .jar file.
i fine using mvn install-file
install .jar local repository, before running mvn install
:
mvn org.apache.maven.plugins:maven-install-plugin:2.5.2:install-file -dfile=lib/my-custom-jar-1.0.0.jar mvn install
however, project on automated build server, mvn clean install
, nil else.
by looking long while, have found several solutions, none perfect.
i writing downwards solutions found reply below, i'm posting question hoping has improve thought solve problem.
here's few solutions tried, weren't great uses:
1. maven-install-pluginthe thought add together install-file goal part of install lifecycle adding pom:
<plugin> <artifactid>maven-install-plugin</artifactid> <version>2.5.2</version> <executions> <execution> <phase>validate</phase> <goals> <goal>install-file</goal> </goals> <configuration> <file>lib/my-custom-jar-1.0.0.jar</file> </configuration> </execution> </executions> </plugin> [...] <dependency> <groupid>org.me</groupid> <artifactid>my-custom-jar</artifactid> <version>1.0.0</version> </dependency>
however, on first goal, validate
, maven seek resolve dependencies before install-file run.
i saw thought of using clean goal. annoyingly, works when separate commands (mvn clean && mvn install
) if both in 1 mvn command (mvn clean install
), maven resolve dependencies first. there solution this?
the idea, seen in stack overflow answer, install-file in parent pom, , add together dependency in kid pom. maven resolve dependencies separately should work.
however project single module, , making false parent solve problem seems over-complication , ugly hack.
3. scheme scope basedir<dependency> <groupid>org.me</groupid> <artifactid>my-custom-jar</artifactid> <version>1.0.0</version> <scope>system</scope> <systempath>${basedir}/lib/my-custom-jar-1.0.0.jar</systempath> </dependency>
although looks made kind of situation, scheme scope expects dependency on every scheme you'll run project, , not packaged in .war, making project non-functional.
4. addjars-maven-pluginthis custom plugin found here includes .jar in .war file, adds pom during compilation.
<plugin> <groupid>com.googlecode.addjars-maven-plugin</groupid> <artifactid>addjars-maven-plugin</artifactid> <version>1.0.5</version> <executions> <execution> <goals> <goal>add-jars</goal> </goals> <configuration> <resources> <resource> <directory>${basedir}/lib</directory> <includes> <include>**/my-custom-jar-1.0.0.jar</include> </includes> </resource> </resources> </configuration> </execution> </executions> </plugin>
this work in normal cases. however, since don't indicate dependency custom .jar in actual pom, ide missing lot of classes, you'll need manually add together custom .jar external library.
this still hacky , not work special cases (hpi:run jenkins debugging illustration throws errors). plus preferred code did not rely on third-party plugins.
5. in-directory maven repositoryi found solution after creating post, , i'm pretty happy it.
this pretty much same result doing mvn install-file
command in question, except save result , maintain part of project installing custom library in repository located within project.
you need pre-install library using command.
mvn org.apache.maven.plugins:maven-install-plugin:2.5.1:install-file \ -dfile=lib/cloudfoundry-client-lib-shaded-1.0.3.jar \ -dlocalrepositorypath=lib
once that's done repository created in lib folder , won't need command ever again.
indicate want utilize repository in pom:
<repository> <id>local repository</id> <url>file://${basedir}/lib</url> </repository> [...] <dependency> <groupid>org.me</groupid> <artifactid>my-custom-jar</artifactid> <version>1.0.0</version> </dependency>
this solution forces commit bunch of folders scm, manageable drawback me , i'm satisfied this.
java maven maven-install-plugin
Comments
Post a Comment