Benjamin Podszun
Benjamin Podszun

Reputation: 9827

mvn dependency:go-offline doesn't download the requirements for maven-surefire-plugin

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.

Upvotes: 8

Views: 8739

Answers (2)

Alberto
Alberto

Reputation: 2982

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

Upvotes: 5

Amol W
Amol W

Reputation: 13

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.

Upvotes: 0

Related Questions