I have a multi-module project in which one of the two submodules depends upon the other. This question implies that mvn install
is supposed to take care of these dependencies.
Everything is working fine at a local level on my machine (both inside Eclipse and on the command line). However, when I update the module which changes code the second module needs and commit to my github repository, the second module fails the Travis CI build. I've traced the problem down to the fact that it is downloading its dependency from a repository rather than using the one it just compiled.
The problem is very similar to the one reported in this question, except that instead of my local repository, I'm dealing with the Travis CI automated build. The comments and answer on that question indicate that:
The dependency has a snapshot version. For snapshots, Maven will check the local repository and if the artifact found in the local repository is too old, it will attempt to find an updated one in the remote repositories.
However, in this case, "too old" shouldn't apply. The local artifact was literally just built. It should be seconds old.
Here are the relevant sections of pom.xml of the oshi-json
module, noting its dependence on oshi-core
(both share their version number with the parent):
<parent>
<groupId>com.github.dblock</groupId>
<artifactId>oshi-parent</artifactId>
<version>3.0-SNAPSHOT</version>
</parent>
<artifactId>oshi-json</artifactId>
<packaging>jar</packaging>
<name>oshi-json</name>
<dependencies>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>oshi-core</artifactId>
<version>${project.version}</version>
</dependency>
</dependencies>
And an excerpt from the parent pom.xml:
<groupId>com.github.dblock</groupId>
<artifactId>oshi-parent</artifactId>
<version>3.0-SNAPSHOT</version>
<packaging>pom</packaging>
<name>oshi-parent</name>
<modules>
<module>oshi-core</module>
<module>oshi-json</module>
</modules>
The complete files are available here:
Relevant excerpts from the log files are shown below. A complete example of a failed Travis CI build can be found here. Note that the symptom (Compilation Error) is a result of Travis using the latest snapshot for oshi-core, which does not include the class referenced in oshi-json; however, the class is in the submitted pull request and it compiles (and builds with mvn install) locally.
When I make a new commit, Travis executes the build as follows:
$ mvn install -DskipTests=true -Dmaven.javadoc.skip=true -B -V
The reactor properly arranges the builds in order:
[INFO] Reactor Build Order:
[INFO]
[INFO] oshi-parent
[INFO] oshi-core
[INFO] oshi-json
The parent builds, and then oshi-core
builds, storing the compiled code locally:
[INFO] Building jar: /home/travis/build/dblock/oshi/oshi-core/target/oshi-core-3.0-SNAPSHOT.jar
This is the jar that I want the next module dependent on. However, when the oshi-json
build starts, it instead downloads the artifact from maven instead:
[INFO] Downloading: https://oss.sonatype.org/content/repositories/snapshots/com/github/dblock/oshi-core/3.0-SNAPSHOT/oshi-core-3.0-20160624.032041-9.jar
[INFO] Downloaded: https://oss.sonatype.org/content/repositories/snapshots/com/github/dblock/oshi-core/3.0-SNAPSHOT/oshi-core-3.0-20160624.032041-9.jar (199 KB at 708.5 KB/sec)
EDIT: Just noticed the following warning which occurs just prior to the download, which may or may not be relevant (an error in Travis settings) however, fixing that warning still doesn't resolve my problem, here's a failed build without the warning:
[WARNING] Failure to transfer com.github.dblock:oshi-core:3.0-SNAPSHOT/maven-metadata.xml from https://nexus.codehaus.org/snapshots/ was cached in the local repository, resolution will not be reattempted until the update interval of codehaus-snapshots has elapsed or updates are forced. Original error: Could not transfer metadata com.github.dblock:oshi-core:3.0-SNAPSHOT/maven-metadata.xml from/to codehaus-snapshots (https://nexus.codehaus.org/snapshots/): nexus.codehaus.org
This is a temporary problem associated only with Travis-CI; the pom setup will work fine once I actually release all the modules, and I can work around it by locally executing mvn clean deploy
to push the new oshi-core
to the OSS repository so Travis is happy. However, this seems a poor workaround.
Is there a way I can tell Travis CI to use the jar that it just compiled rather than downloading a new one -- and to do so in a way that doesn't break the intended download of the dependency from the repository once it's published?