Is there a good reason why Apache’s Maven enforcer plug-in demands v.3.8.6? - maven

When studying a course on how to use the Jenkins CI tool I encountered an issue that 3.6.3 is the latest version that we can install, but Apache’s Maven enforcer plug-in demands 3.8.6.
Does anyone know why there is this discrepancy? Thank you.
I ran apt-get install maven in my command prompt, and was able to install maven 3.6.3.
"maven is already the newest version (3.6.3-5)"
The error message was:
[info] --- maven- clean- plugin: 2.5: clean. (default- clean) # my- app ---
[info] --- maven- enforcer- plugin: 3.1.0: enforce (enforce- maven) # my-app ---
[Error] Rule 0: org.apache.maven.plugins.enforcer.RequireMavenVersion failed with message: Detected Maven version 3.6.3 is not in the allowed range [3.8.6).
Presumably there is a version 3.8.6 out there somewhere if the plug-in enforcer expects one.

Thank you very much for directing my attention to the POM! Therein lies the issue! The Maven plugin enforcer lies within the POM. I have updated it from 3.8.6 to 3.6.3. Thank you for leading me to the answer.
<rules>
<requireMavenVersion>
<version>[3.8.6,)</version>
</requireMavenVersion>
<requireJavaVersion>
<version>[11,)</version>
</requireJavaVersion>
</rules>

Related

How to fix not finding a plugin artifact?

I am getting this error: [ERROR] Plugin org.apache.maven.plugins:maven-surefire-plugin:2.12.4 or one of its dependencies could not be resolved: Could not find artifact org.apache.maven.plugins:maven-surefire-plugin:jar:2.12.4 in nexus-xyz-plugin
I tried to run maven with dependecy:tree, but I can't see surefire, and I dont know why it is looking for this specific version 2.12.4 which is not specified in my pom!
Even the surefire plugin is not defined in my pom, but I have the assembly plugin not sure if assembely is dependent on surefire
Note that I only get the error when running mvn package, however when running mvn compile the build succeeds
Version 2.12.4 of the maven-surefire-plugin is always added to the pom by maven version 3.x unless you depend on a specific other version.
Maven has a so called super pom that you get for free, but that doesn't list surefire: https://maven.apache.org/ref/3.8.5/maven-model-builder/super-pom.html
However it is added to the pom, i've checked this with maven 3.3.9. You can verify this by running mvn help:effective-pom.
Reference with the same problem: No surefire plugin in my pom - How does it show surefire output?
These plugin versions are part of the default bindings for lifecycle executions, in this case of the test phase. So these plugins are always included if not specified.
See for reference:
https://maven.apache.org/guides/introduction/introduction-to-the-lifecycle.html
https://maven.apache.org/ref/3.8.5/maven-core/default-bindings.html
Maven default life-cycle and plugins section
Normally this plugin should be available in maven central, check if you have a <pluginRepository> in your (effective) pom that references https://repo1.maven.org/maven2/
Some other things you can check:
Open the file .m2\repository\org\apache\maven\plugins\maven-surefire-plugin\2.12.4\maven-surefire-plugin-2.12.4.jar.lastUpdated and check the error message for each repository. Check why it can't reach maven central; is it missing from the list or giving an error? This might be a company firewall/policy issue perhaps? Or is it giving an error on HTTPS/TLS protocol level?
Check if you can add maven central to your repositories list if it's missing somehow (should be included by default). Check if it's HTTP or HTTPS, only secure is supported now.
Run your maven command with -X for debug mode to investigate further
An alternative is to add the latest version of surefire to your project that is available in your plugin-repository, and perhaps disable it if you're not executing unit tests.
See Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.12:test (default-test) on project.

Maven downloading surefire plugin 3.0.0-M2 inspite of not been specified in pom

We were building one of the projects with surefire plugin version with Maven 3.0.4 and Java 1.7 . Recently we changed to build code with Maven 3.3.9 and Java 1.8 . But we cam across NestedException issue which we resolved by adding surefire plugin version 3.0.0-M2 within pom.xml. But due to certain conditions we had to revert to the same old Maven i.e. 3.0.4 and Java 1.7 and we removed the surefire plugin entry with version 3.0.0-M2 within pom. But the build is still downloading 3.0.0-M2 version surefire and using it and its failing the build with guice exception. We cleared the repo, removed from nexus but it is still downloading . There is no entry within pom for this plugin why is it still downloading the surefire 3.0.0-M2 version . Please help .
#alim-azad What conditions forced you to downgrade the version 3.0.0-M2? The CI is testing it against Maven 3.2+. Downgrading to such very low version of Maven is a risk that you wont be able to step out of issues fixed in higher versions.

Spring-core dependency version error with a Jenkins Plugin

I'm trying to make a Jenkins plugin that uses a library that requires spring-core 3.2.2 (cloudfoundry-client-lib). I simply used the mvn command to create a skeleton plugin, then added my Maven dependency to pom.xml and a few simple code lines that uses the library. I'm not getting any problem running the skeleton plugin without my dependency.
Upon compiling with "mvn package", I'm getting a test error:
WARNING: Failed to scout hudson.security.PAMSecurityRealm
java.lang.InstantiationException: java.lang.NoClassDefFoundError: org/springframework/core/env/EnvironmentCapable
Looks like this is a class that appeared in spring-core 3.1.0. So I looked at the Maven dependency tree:
[INFO] --- maven-dependency-plugin:2.3:tree (default-cli) # stackato-jenkins ---
[INFO] org.wiwiweb:cf-test-jenkins:hpi:1.0-SNAPSHOT
[INFO] \- org.cloudfoundry:cloudfoundry-client-lib:jar:1.0.2:compile
[INFO] \- org.springframework:spring-webmvc:jar:3.2.2.RELEASE:compile
[INFO] \- org.springframework:spring-core:jar:2.5.6.SEC03:compile
So Maven tells me it's using spring-core 2.5.6 because of spring-webmvc 3.2.2? This is strange because, looking online, spring-webmvc 3.2.2 depends on spring-core 3.2.2. Looking at the verbose version of the tree, looks like jenkins-core depends on spring-core 2.5.6... This makes me suspicious that the problem is from Jenkins.
Anyway, if it's just a version conflict, then overriding Maven's decision by explicitly saying I want spring-core 3.2.2 in my pom.xml should solve the problem, right?
I did this, then did not get a compile error. Problem solved!... not.
In runtime, after activating this plugin in Jenkins and running a build with this, as soon as the code runs into a line that uses the library I added, the Jenkins output tells me this:
FATAL: org.springframework.util.CollectionUtils.unmodifiableMultiValueMap(Lorg/springframework/util/MultiValueMap;)Lorg/springframework/util/MultiValueMap;
java.lang.NoSuchMethodError: org.springframework.util.CollectionUtils.unmodifiableMultiValueMap(Lorg/springframework/util/MultiValueMap;)Lorg/springframework/util/MultiValueMap;
UnmodifiableMultiValueMap() is a method that was added in spring-core 3.1, so this means Jenkins is still trying to run my plugin with the old version of spring-core, even though I explicitly said I wanted the newest one in my plugin's pom.xml!
So I'm stuck on this. I'm not even sure if it's a Maven or a Jenkins issue. I'll sum up the whole thing in two questions:
Why is Maven not compiling the plugin with a correct version of spring-core unless I explicitly tell him to? It should be able to follow dependencies without me giving it hints.
Why is Jenkins running my plugin with an older version of spring-core than the one it was compiled with, and how can I make it use the correct one?
If you're picking up dependencies from the Jenkins install rather than from your plugin the solution is actual quite easy to implement. Per the Jenkins documentation, simply add the maven-hpi-plugin to the build in the pom.xml of your Jenkins plugin and set it to load the plugin classes first:
<build>
<plugins>
<plugin>
<groupId>org.jenkins-ci.tools</groupId>
<artifactId>maven-hpi-plugin</artifactId>
<configuration>
<pluginFirstClassLoader>true</pluginFirstClassLoader>
</configuration>
</plugin>
</plugins>
</build>
Try to "shade" the CF client lib using the Maven Shade plugin, as it seems Jenkins doesn't like plugins that are using a different version of Spring than the one it uses internally itself.
Even if your own plugin doesn't use Spring directly, but the CF library does, I believe this still applies. The person that suggested shading in the jenkinsci-dev mailing list seems to be involved in Jenkins plugins development, so he might know about this more than others.
These being said, I would get the source code for cf-client-lib, I would change the pom.xml to consider shading for org.springframework package, as well (because cf-client-lib already uses shading for org.codehaus.jackson package) and I would use this "shaded" version of cf-client-lib in the Jenkins plugin.

Where to add dependencies in MAVEN multi-module project

I am trying to make sense of all the dependency thing in maven multiple module projects. As a starting point I used appfuse to create a new spring mvc multi-module project. It initially has web and core modules.
I found the knowledge of deploying this project. But when I get an error. I am confused of where to add a dependency or a plugin always. I would like to clarify with the following issue.
I created a appfuse mvc multimodule project. I maven installed the core and then maven jetty7:run on web (initially I ran mvn install on root folder and then I tied to mvn tomcat:run on the same folder. But it has to be done as below.
mvn install on core folder
mvn tomcat7:run on web folder
I initially got an error like missing prefix "Tomcat7". I resolved it by adding the following plugin to the pom in web.
<plugin>
<groupId>org.apache.tomcat.maven</groupId>
<artifactId>tomcat7-maven-plugin</artifactId>
<version>2.0</version>
</plugin>
And that error was resolved. But I was unsure about that because I can add the plugin to the parent pom. Then I ran again mvn tomcat7:run on web file and now I am getting the following error.
[INFO] >>> tomcat7-maven-plugin:2.0:run (default-cli) # test-web >>>
[WARNING] The POM for org.aspectj:aspectjweaver:jar:1.8.0.M1 is missing, no depe
ndency information available
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
I am not sure where to add the dependency to which pom. I would like know some basics of how the poms can work together to do the installation. For example, There is also a parent pom. But I am not doing a mvn install or anything on the parent pom. I am going to the core and do a mvn install and then go to the web and do a mvn tomcat7:run
I this case how the parent pom contribute to the installation and ruining process? and how should I resolve the above warning and resolve the error.
Some informative answer is very much appreciated. Thanks
You should add the Tomcat plugin to the web project as it will only work in a project that's type "war". There should already be a jetty plugin configured, so "mvn jetty:run" should work from the web folder.

Unable to load the mojo - maven install

I am trying to install a maven project at work and getting the following error. A bit of googling shows other people with the mojo problem, but none with the specific maven-war-plug and MavenFilteringException.
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-war-plugin:2.1.1:war (default-war) on project genericIntegrationServer: Executio
n default-war of goal org.apache.maven.plugins:maven-war-plugin:2.1.1:war failed: Unable to load the mojo 'war' in the plugin 'org.apache.maven.plugin
s:maven-war-plugin:2.1.1'. A required class is missing: org/apache/maven/shared/filtering/MavenFilteringException
Apache Maven 3.0.3 (r1075438; 2011-02-28 17:31:09+0000)
Maven home: C:\dev\apache-maven-3.0.3\bin..
Java version: 1.6.0_19, vendor: Sun Microsystems Inc.
Java home: c:\dev\jdk\1.6\1.6.0_19\jre
Default locale: en_GB, platform encoding: Cp1252
OS name: "windows 7", version: "6.1", arch: "x86", family: "windows"
I had same issue. However, after running {Maven->Update Project} resolved the issue.
When I had this problem, it seemed to be a problem with my Maven install.
Uninstalling the M2Eclipse plugin and deleting the .m2 folder on my drive, then reinstalling M2Eclipse seemed to fix it.
I just ran into this problem or something very similar:
Unable to load the mojo 'resources'
I had just renamed some view files and had two path related errors in STS / Eclipse which I fixed but after fixing them a red X appeared next to the war line in the POM file.
"Project -> Clean" didn't help.
"Maven -> Update Project" did the trick though and cleared the error message.
I fixed this problem by doing a maven update and force Update of Snapshots/Releases
maven > update Maven Project > force Update of Snapshots/Releases
Yes, force update of Snapshots/Releases works for me. And I think it's an easy way to fix this problem.
I had the same issue and was able to resolve this error in Eclipse by doing an Maven->Update Project and checking the 'Force Update of Snapshots/Releases' check box. Without checking 'Force Update of Snapshots/Releases' though I continued to get the same errors.
The problem is solved by adding a plugin
<build>
<finalName>some_name</finalName>
<pluginManagement>
<plugins>
<plugin>
<artifactId>maven-war-plugin</artifactId>
<version>3.2.2</version>
</plugin>
</plugins>
</pluginManagement>
I experienced a related problem (and ended up at this question after googling).
When building from Eclipse using the Maven plugin (Run As... -> Maven install), it was failing with the following error:
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-resources-plugin:2.4.1:resources (default-resources) on project [project-name]: Execution default-resources of goal org.apache.maven.plugins:maven-resources-plugin:2.4.1:resources failed: Unable to load the mojo 'resources' in the plugin 'org.apache.maven.plugins:maven-resources-plugin:2.4.1'. A required class is missing: org/apache/maven/shared/filtering/MavenFilteringException
(also seen in this coderanch post)
Building from the command line worked fine, and I noticed that in that case it was using maven-resources-plugin version 2.4.3 and not 2.4.1.
In the end I fixed this by uninstalling and then reinstalling the M2Eclipse plugin (ver. 0.12.1) like Kevin suggested. (It seemed to work without deleting the .m2 folder)
I'm thinking the corruption might have happened when I exited Eclipse while it was in the middle of "Updating Indexes...".
I had a similar problem so I deleted only the folder maven folder at ~/.m2/repository/org/apache/maven and worked for me.
All maven libraries was downloaded and the error with MavenFilteringException stopped happened.
Just close and reopen the project
for me it solved the problem adding
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>3.3.2</version>
</plugin>
as I use
<packaging>war</packaging>
I resolved this issue running clean install.
Navigate to the project root directory in terminal and run mvn clean install.
Then refresh the eclipse project. That's it.
I simply resolved this issue by deleting the repository folder in .m2, then running mvn clean install. In my case, the downloading of dependencies was aborted due to my machine shutting down, so I think one of the plugins were corrupted. Hope this helps someone.
For me, my maven was outdated in the bundle. I was using netbeans. So I first found where my maven was installed by using mvn -version and then copying the location. Then, on MACOS, I went to Netbeans --> Preferences --> Java and then Maven to finally set the maven Home to where maven is installed!
My issue got resolved by doing
Project (right click) -> Maven -> Update Project..

Resources