We have an internal company Artifactory server for our Maven dependencies. We have a dedicated Maven project with test cases and some of our internal libraries are used in this project. The Artifactory server is reachable from our CI so all the artifacts can be pulled during build process.
Our goal is to run the tests from that project in Docker container in a private cluster without access to internal repository - for practical purposes, we can assume that mvn test is invoked offline.
That means that as part of the build process, I want to package test project and all required dependencies into an Docker image so that I can run tests safely in offline environment without need to pull anything.
The current approach is to make sure that .m2 repo is part of the image and then invoke this command in Dockerfile:
mvn clean install -DskipTests
The command downloads many Maven plugins (so that they are in .m2/repository now).
Then in the test environment I invoke:
mvn test -o
However, the latter command produces error when running the container:
[INFO] Scanning for projects...
(...)
[INFO]
[INFO] Building test-project 1.0.0
[INFO] --------------------------------[ jar ]---------------------------------
[INFO]
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ test-project ---
[WARNING] Using platform encoding (UTF-8 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] skip non existing resourceDirectory /workspace/test-project/src/main/resources
[INFO]
[INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ test-project ---
[INFO] No sources to compile
[INFO]
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ test-project ---
[WARNING] Using platform encoding (UTF-8 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] Copying 2 resources
[INFO]
[INFO] --- maven-compiler-plugin:3.1:testCompile (default-testCompile) @ test-project ---
[INFO] Nothing to compile - all classes are up to date
[INFO]
[INFO] --- maven-surefire-plugin:2.22.2:test (default-test) @ test-project ---
[WARNING] Missing POM for org.apache.maven.surefire:surefire-junit-platform:jar:2.22.2
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1.908 s
[INFO] Finished at: 2019-12-12T07:43:40Z
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.22.2:test (default-test) on project test-project: Unable to generate classpath: org.apache.maven.artifact.resolver.MultipleArtifactsNotFoundException: Missing:
[ERROR] ----------
[ERROR] 1) org.apache.maven.surefire:surefire-junit-platform:jar:2.22.2
[ERROR]
[ERROR] Try downloading the file manually from the project website.
[ERROR]
[ERROR] Then, install it using the command:
[ERROR] mvn install:install-file -DgroupId=org.apache.maven.surefire -DartifactId=surefire-junit-platform -Dversion=2.22.2 -Dpackaging=jar -Dfile=/path/to/file
[ERROR]
[ERROR] Alternatively, if you host your own repository you can deploy the file there:
[ERROR] mvn deploy:deploy-file -DgroupId=org.apache.maven.surefire -DartifactId=surefire-junit-platform -Dversion=2.22.2 -Dpackaging=jar -Dfile=/path/to/file -Durl=[url] -DrepositoryId=[id]
[ERROR]
[ERROR] Path to dependency:
[ERROR] 1) dummy:dummy:jar:1.0
[ERROR] 2) org.apache.maven.surefire:surefire-junit-platform:jar:2.22.2
[ERROR]
[ERROR] ----------
[ERROR] 1 required artifact is missing.
[ERROR]
[ERROR] for artifact:
[ERROR] dummy:dummy:jar:1.0
[ERROR]
[ERROR] from the specified remote repositories:
[ERROR] central (http://company-repo.org/artifactory/plugins-release, releases=true, snapshots=false),
[ERROR] snapshots (http://company-repo.org.org/artifactory/plugins-snapshot, releases=true, snapshots=true)
[ERROR]
[ERROR] -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException
I'm not sure if dummy.jar is part of my project setup but I think that error can be ignored.
It seems to me that org.apache.maven.surefire:surefire-junit-platform plugin is not available. And when I looked at the build command output I confirmed that it succeeds without ever invoking this plugin (and so without ever pulling it to local repository):
mvn clean install -DskipTests
(...)
[INFO] --- maven-surefire-plugin:2.22.2:test (default-test) @ test-project ---
[INFO] Tests are skipped.
[INFO]
[INFO] --- maven-jar-plugin:2.4:jar (default-jar) @ test-project ---
(...)
So the problem is: how do I prepare Maven to run tests in "offline" mode without actually running the tests?
-Dtest with "match-nothing" pattern but the plugin wasn't pulled (apparently it activates only if there are some tests to run)mvn dependency:go-offline which pulled in hundreds of dependencies but not those for testHave a look to https://github.com/qaware/go-offline-maven-plugin, maybe it can help. It has been developed to fix some issues of the maven-dependency-plugin.
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