I have to unpack some dependencies from a remote location and install them locally.
I successfully get them (using the antrun plugin) and install them (using the install plugin)
However, if I define them as dependencies (<dependency>..</dependency>
) maven first tries to resolve them, and only then, if succeeds, proceeds to the antrun and install.
I also tried the build-helper-plugin and its attach-artifact, but it doesn't do anything (it doesn't even add the artifacts to the final war file)
So, how to run my executions before maven attempts to resolve dependencies?
We can use -U/--update-snapshots flag when building a maven project to force maven to download dependencies from the remote repository. Here, -U,--update-snapshots : Forces a check for missing releases and updated snapshots on remote repositories.
When you run a Maven build, then Maven automatically downloads all the dependency jars into the local repository. It helps to avoid references to dependencies stored on remote machine every time a project is build.
Interesting question! One attempt to (maybe) achiv this is to use a Multi Module Project setup.
Fetch and install your dependencies in the parent project and use them in the child module. I tested my assumption like this:
Parent pom.xml
<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/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>foo.bar</groupId>
<artifactId>foo.bar.parent</artifactId>
<version>1.0.0</version>
<packaging>pom</packaging>
<modules>
<module>foo.bar.child</module>
</modules>
<build>
<plugins>
<plugin>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.6</version>
<executions>
<execution>
<phase>validate</phase>
<configuration>
<target>
<echo
message="Hello world!" />
</target>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
Module pom.xml
<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/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>foo.bar</groupId>
<artifactId>foo.bar.child</artifactId>
<version>1.0.0</version>
<parent>
<groupId>foo.bar</groupId>
<artifactId>foo.bar.parent</artifactId>
<version>1.0.0</version>
</parent>
<dependencies>
<dependency>
<artifactId>can.not</artifactId>
<groupId>find.me</groupId>
<version>0.0.0</version>
</dependency>
</dependencies>
</project>
I get the "Hello World" output from the parent pom build before the child module build fails (because of missing dependency). If you achiev to provide the dependency in the parent.pom's build the child module project should be buildable.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With