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

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.

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

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.

Related

Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin: 3.0.0-M4 (default-test). There are test failures- JENKINS

I did download the project from github without any problem, i provided th maven commands mvn clean install and the project build successfully but when it comes to run the tests i get the following error. Any hints? I'am providing my pom.xml file, i tried all the suggestions but nothing.
Does your pom.xml contains the plugin surefire tag ? If thats missing then maven wont download this plugin at runtime and hence the error. Also if its there but maven cant download then may be you have to allow internet connectivity or copy the jars manually inside the .m2 directory on the Jenkins/Node server machine.
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.12.4</version>
</plugin>

Maven dependencies inside tar.gz file

So I have the following tar.gz file in my repo with structure as:
> A.tar.gz
> |
> |____ a.tar.gz
> |
> |____ b.tar.gz
> |
> |_____ folderA
> |
> |_____ folderB
> |
> |______ jar1.jar
> |
> |______ jar2.jar
Now in my POM file for another project I would like to add the jar1 and jar2 as dependencies. So far I have the following:
<dependency>
<groupId>com.groupid</groupId>
<artifactId>master</artifactId>
<version>18.1</version>
<type>tar.gz</type>
<classifier>bin</classifier>
</dependency>
This made the tar file available. I then tried to unpack as:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<phase>generate-resources</phase>
<goals>
<goal>unpack-dependencies</goal>
</goals>
<configuration>
<includeTypes>tar.gz</includeTypes>
<includeArtifactIds>master</includeArtifactIds>
<outputDirectory>target/somefolder</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
However, on running the build, I still don't get the jars as dependencies. I am sure I am missing something , so any help appreciated!
So you have JAR dependencies located inside another tar.gz dependency that you want in your project. So far so good, the problem is you're trying to:
Make the the first .tar.gz dependency available (OK)
Launch the build to unpack the jars (OK)
Add unpacked jar as dependencies during the same build (Not possible)
All in one run. That is not possible in Maven by design (to the best of my knowledge). Even if you did find a way to do it this way, that would over-complexify your build and break Maven design, probably leading to other issues.
You mentioned that you don't control the packaging of the other team and it seems you can't upload said dependencies on a Nexus repo either. What you can do is make the JAR dependencies available in your local repo prior to running your build by doing something like:
Download your tar.gz file and unpack it
Install the jar dependencies in your local Maven repo using commands like mvn install:install-file -Dfile=path/to/jar1.jar -DgroupId=com.mycompany -DartifactId=jar1 -Dversion=1.0.0 -Dpackaging=jar with proper version, groupdId and artifactId for each jars (see the Guide to installing 3rd party JARs for more details)
Now you can run your your original project only by mentioning your jar dependencies as <dependency>
With this you will manually install your jar dependencies in your Maven local repository, rendering them available to your project without needing a Nexus repository or further unpackaging. You can perform step 1 and 2 manually or by creating another Maven project that you will have to run once before running your main project. To do so you can create a new project and use the maven-dependency-plugin as you already did coupled with the maven-exec-plugin to run the mvn install:install-file command.
Note this process must be done for every individual machine on which you will run your project. As #khmarbaise mentioned, it's best to have your dependencies available directly through a repository manager such as Nexus without having to perform additional steps, but this temporary workaround should work just fine.

"Artifact is not fully assembled" error with maven-invoker-plugin in parallel build

According to the docs, maven-invoker-plugin is "thread-safe and supports parallel builds." However, when I build by multi-module project with -T 1C, I get an error like the following:
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-invoker-plugin:1.10:install (integration-test) on project my-archetype: Failed to install project dependencies: MavenProject: com.tavianator:my-archetype:1.6-SNAPSHOT # /home/tavianator/code/Project/my-archetype/pom.xml: Failed to install project artifacts: MavenProject: com.tavianator:my-project:1.6-SNAPSHOT # /home/tavianator/code/Project/my-project/pom.xml: Failed to install artifact: com.tavianator:my-project:jar:1.6-SNAPSHOT: Artifact is not fully assembled: /home/tavianator/code/Project/my-project/target/classes -> [Help 1]
The project layout is like this:
Root
|--Project 1
|--Project 2
|--Archetype (depends on Project 1, scope=test)
The archetype integration tests use the maven-invoker-plugin to install the relevant dependencies (Root and Project 1) to a local repository, then runs the normal archetype integration tests. In parallel builds, Archetype and Project 2 run at the same time. When the maven-invoker-plugin runs, it tries to install Project 2 to the local repo, but Project 2 isn't built yet, hence the error.
But since Project 2 isn't even needed for the tests, I should be able to work around the problem by explicitly installing only the needed dependencies. I don't see how to get the invoker plugin to do that, but is there another plugin I can use?
I reported the maven-invoker-plugin bug here. I have an example project that demonstrates the error here.
I ran into this problem as well, in addition to other problems with the setup suggested in Fast Build Configuration (such as some artifacts being downloaded by the invoked project in every run), and implemented my own solution. Instead of the invoker:install goal, you would use the following:
<plugin>
<groupId>com.github.veithen.invoker</groupId>
<artifactId>resolver-proxy-maven-plugin</artifactId>
<version>0.1</version>
<executions>
<execution>
<goals>
<goal>start</goal>
<goal>stop</goal>
</goals>
</execution>
</executions>
</plugin>
Note that there is no need to explicitly configure settings.xml or a dedicated local repository. This is done automatically.
Currently the code in the plugin is experimental. If it turns out to be robust enough, I will submit a patch integrating it into maven-invoker-plugin. More information here.

Sonar 4.1.1 maven plugin can't be resolved

I'm using SonarQube 4.1.1 and have the following configuration in my pom.xml file:
<pluginManagement>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>sonar-maven-plugin</artifactId>
<version>4.1.1</version>
</plugin>
</plugins>
</pluginManagement>
When I try to run sonar from the command line using the maven plugin I get:
[ERROR] Plugin org.codehaus.mojo:sonar-maven-plugin:4.1.1 or one of its dependencies could not be resolved: Failed to read artifact descriptor for org.codehaus.mojo:sonar-maven-plugin:jar:4.1.1: Failure to find org.codehaus.mojo:sonar-maven-plugin:pom:4.1.1 in http://repo.maven.apache.org/maven2 was cached in the local repository, resolution will not be reattempted until the update interval of central has elapsed or updates are forced -> [Help 1]
Anyone know how to fix this issue? Do I need to make some configuration changes?
In fact this configuration is not needed. Have you try to run an analysis without it? You should give a try if you haven't.
But if you really need to force the version of the sonar-maven-plugin, you should set it to 2.1 on Maven 3.
See http://docs.codehaus.org/display/SONAR/Analyzing+with+Maven for more details.
Regards
Try this:
mvn clean sonar:sonar -U
The -U flag means force update of dependencies.

Wro4j maven plugin - required class is missing

I'm trying to run wro4j maven plugin according to the documentation
I add the plugin to my pom.xml:
<plugin>
<groupId>ro.isdc.wro4j</groupId>
<artifactId>wro4j-maven-plugin</artifactId>
<version>1.5.0</version>
</plugin>
and run the goal:
mvn wro4j:run -Dminimize=true -DtargetGroups=all
However the build fails with error:
org.apache.maven.lifecycle.LifecycleExecutionException: Internal error in the pl
ugin manager executing goal 'ro.isdc.wro4j:wro4j-maven-plugin:1.5.0:run': Unable
to load the mojo 'ro.isdc.wro4j:wro4j-maven-plugin:1.5.0:run' in the plugin 'ro
.isdc.wro4j:wro4j-maven-plugin'. A required class is missing: org/codehaus/plexu
s/util/Scanner
Do you know how to avoid this error?
Since wro4j-1.5.0, the maven 3.0 is required to run the plugin. The reason is a feature called incremental build support which depends on a library which is not available on older version of maven by default.
The issue is on your local environment.
Go to this folder on my windows machine:${user.home}/.m2/repository, then delete everything in this folder. (Well you can keep a copy.)
After deleting, run the Maven command:mvn clean install -U.
See: https://groups.google.com/forum/#!topic/wro4j/ZPSFBQ_5lI8

Resources