6

I'm trying to build an open source project in docker and want to save time spent on builds, so I tried using mvn dependency:go-offline, which does download maven-surefire-plugin itself.

Running mvn -o clean package afterwards results in

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:3.0.0-M4:test (default-test) on project oxalis-api: Execution default-test of goal org.apache.maven.plugins:maven-surefire-plugin:3.0.0-M4:test failed: Plugin org.apache.maven.plugins:maven-surefire-plugin:3.0.0-M4 or one of its dependencies could not be resolved: Cannot access apache.snapshots (http://repository.apache.org/snapshots/) in offline mode and the artifact org.codehaus.plexus:plexus-utils:jar:1.1 has not been downloaded from it before. -> [Help 1]

(I've enabled the snapshots repository because maven-dependency-plugin has serious issues with multi module projects otherwise)

The POM includes

        <pluginManagement>
            <plugins>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-surefire-plugin</artifactId>
                    <version>3.0.0-M4</version>
                    <configuration>
                        <useSystemClassLoader>false</useSystemClassLoader>
                    </configuration>
                </plugin>
            </plugins>
        </pluginManagement>

and as described above, that plugin itself does exist in my repository after go-offline.

Benjamin Podszun
  • 9,679
  • 3
  • 34
  • 45
  • What about `mvn clean && mvn dependency:go-offline && mvn -o package`? – PiRocks Nov 21 '19 at 10:42
  • I think you have something else that is miss-configured and it comes out as this symptom. The error message says that it's trying to download the released artefact `org.codehaus.plexus:plexus-utils:jar:1.1` from a snapshot repo, which is plain wrong. – Augusto Nov 21 '19 at 10:45
  • @PiRocks I start in an empty container, there's nothing to clean. – Benjamin Podszun Nov 21 '19 at 10:49
  • 1
    @Augusto that makes sense, but.. this is AFTER go-offline. I'd expect go-offline to try and grab all dependencies (and fail potentially)? – Benjamin Podszun Nov 21 '19 at 10:50
  • @Benjamin My concern was that go offline wasn't downloading to a global repository and was instead downloading locally, so running clean before package was deleting whatever you had downloaded. – PiRocks Nov 21 '19 at 10:51
  • @BenjaminPodszun Your assumption is correct, as long as the configuration is correct too. There's something wrong in the repo configuration of Maven. Maven should never look for a released version of an artefact in a snapshot repository. Something in the configuration is confusing Maven. It might help if you add the repo configuration of `apache.snapshots` that you have in your pom or settings.xml. – Augusto Nov 21 '19 at 10:55

2 Answers2

4

It seems that your maven local repository uses the legacy structure, details here. So the goal dependency:go-offline prepares the repository in the legacy mode, then the actual goal for building package cannot find the dependency because it uses the default mode.

So for your specific scenario you can use the following command to download the dependencies and the plugins in batch mode:

mvn dependency:resolve-plugins dependency:go-offline -B 

And you can use the following for the build, with the offline, batch and legacy local repository options:

mvn package -o -llr -B

Hint: if you need additional plugin or dependencies in your build that are not explicitly defined in the main pom, like the ones you add during the build (i.e. clover, allure, pact, etc) you can pre download using the following command:

mvn dependency:get -Dartifact=org.openclover:clover-maven-plugin:4.4.1 -B

Hint 2: If you have issues when offline and the dependencies are not taken maybe it is because you have different maven settings when you download the dependencies and when you build your project. You can consider to delete the maven-metadata*.xml and _*.repositories inside the local repository, you can use this:

find ~/.m2/repository -name 'maven-metadata*.xml' | xargs -n1 rm
find ~/.m2/repository -name '_*.repositories' | xargs -n1 rm
Alberto
  • 2,881
  • 7
  • 35
  • 66
0

I too was facing the same issue, changed the version from 3.0.0-M4 to 2.12 and it worked for me. I am still trying to figure out why its not working with 3.0.0-M4.

Amol W
  • 13
  • 2