My Maven project depends on two other jars.
I cannot load these two jars on any Maven repo so I would like to download the sources from GitHub and install them locally on the fly when I run the install phase on my project.
Currently I'm using bootstrap goal of maven-scm plugin hooked to validate phase of default lifecycle but the problem is that I have to run mvn validate first and then mvn install, because if I directly run the mvn install, Maven realizes that the artifacts are not present and goes immediately in error:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-scm-plugin</artifactId>
<version>2.0.0-M3</version>
<configuration>
<mavenHome>${maven.home}</mavenHome>
<goals>install</goals>
</configuration>
<executions>
<execution>
<id>clone_and_install_1st_dependency</id>
<phase>validate</phase>
<configuration>
<connectionUrl>scm:git:https://github.com/my_git/1st_dependency.git</connectionUrl>
<scmVersionType>tag</scmVersionType>
<scmVersion>${1st_dependency.version}</scmVersion>
</configuration>
<goals>
<goal>bootstrap</goal>
</goals>
</execution>
<execution>
<id>clone_and_install_2nd_dependency</id>
<phase>validate</phase>
<configuration>
<connectionUrl>scm:git:https://github.com/my_git/2nd_dependency.git</connectionUrl>
<scmVersionType>tag</scmVersionType>
<scmVersion>${2nd_dependency.version}</scmVersion>
</configuration>
<goals>
<goal>bootstrap</goal>
</goals>
</execution>
</executions>
</plugin>
Is there a way to do all this only with mvn install?
Thanks a lot!
CodePudding user response:
No, Maven does not support this.
Dependencies must be present at the very beginning of your Maven run, they cannot be created on the fly.
If you want something like that, use a CI like Jenkins, GitHub Actions etc.