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

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.

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>

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.
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.

Maven Compile Access Denied Copying Dependencies

I have a weird problem with Maven that I've not run into before. I appear to be the only one having the problem on my team and this is for a project that has existed for a significant period of time (10+ years). I'm new to the team, but so are other members who do not seem to be having this problem.
Here's the problem:
If I do a mvn clean compile, I get the following error:
[ERROR] Failed to execute goal org.codehaus.mojo:dependency-maven-plugin:1.0:copy (copy-dependencies)
on project deployable-war: Error copying artifact
from C:\...\dependency\target\classes
to C:\...\deployable-war\target\dependency\jws\lib\classes:
C:\...\dependency\target\classes (Access is denied) -> [Help 1]
Now, the weird part is that source and destination folders (dependency\target\classes and deployable-war\target\dependency\jws\lib\classes) were both created by Maven during the same compile command. This is a multi-module project, so mvn compile will go through all 9 modules. This is module 8. The dependency module is module 7.
If I re-run mvn compile (without the clean) afterwards, it gives the same error, so it does not seem to be a timing issue.
If I manually create the folder (mkdir ...\deployable-war\target\dependency\jws\lib\classes) and re-run mvn compile, everything works fine. That includes it copying JAR files inside of the lib folder that it said was access denied when it tried to create the classes folder.
I've tried deleting the \target\ folder entirely.
I've tried running Maven as an administrator.
I've tried checking out a new copy of the project from Git into a new directory on my local.
I've checked folder permissions on the project itself to ensure that my user and the administrator user have full control.
OS is Windows 10 Enterprise.
Any suggestions?
EDIT: From discussion, tracked the error down to this part of the pom.xml for the module:
<build>
<finalName>deployable</finalName>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>dependency-maven-plugin</artifactId>
<executions>
<execution>
<id>copy-dependencies</id>
<phase>compile</phase>
<goals>
<goal>copy</goal>
</goals>
<configuration>
<outputDirectory>${project.build.directory}/${project.build.finalName}/jws/lib</outputDirectory>
<artifactItems>
<artifactItem>
Now, the issue appears to be related to a subset of the artifactItem - particular, artifactItems that do not have explicitly-defined destFileNames.
Long time coming back to this, but Gerold's comment lead me to the right resolution. The problem was the copy-dependencies happens after package. So the problem was that I was mvn clean compile, when I needed to be mvn clean package
I limped along taking way too long to sort that out. The fun of multi-module, interdependent projects

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

How to distribute a binary dependency in maven?

I'm trying to convert a project from ant to maven.
The unit tests depend on a third party binary jar, which is not available in any public maven repositories.
How do I make maven handle this situation? I have found two solutions, neither of which are acceptable. First is to use a system dependency; this doesn't work because a) the dependency should only be for the tests, and b) the dependency is not found by eclipse after generating an eclipse project.
Second is to manually install the dependency in a local repository. This seems to be the recommended way. I don't want to do this because I want users to be able to build and test with a simple 'mvn test'. If users have to read a document and copy/paste some shell commands to be able to build and test, then something's wrong.
I suppose it would be OK if maven itself installed the dependency in the local repository as part of the build - is this possible, and if so, how?
Aled.
You may want to look at install:install-file. You can make it execute in the early phase of your project (validate or initialize) via standard means.
On the second thought, if it fails because of missing dependency in the same project, there are couple more options. One is to call ant script via antrun plugin to install artifact.
Or create additional module not dependent on your artifact to be executed prior to main module and have that module install artifact as described earlier.
First of all my way would be using a repository manager such as nexus and installing this dependency to there.
However there is another solution. You can include this 3rd party jar to your project and with test plugin you can configure to include it in classpath such this:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.10</version>
<configuration>
<additionalClasspathElements>
<additionalClasspathElement>path/to/additional/resources</additionalClasspathElement>
<additionalClasspathElement>path/to/additional/jar</additionalClasspathElement>
</additionalClasspathElements>
</configuration>
</plugin>
By the way, I hope that you are aware of that maven is executing surefire plugin in order to run tests by default lifecycle.

Resources