2
votes

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.

2
What about mvn clean && mvn dependency:go-offline && mvn -o package?PiRocks
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
@PiRocks I start in an empty container, there's nothing to clean.Benjamin Podszun
@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
@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

2 Answers

0
votes

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.

0
votes

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