Can we use dependency version range for maven plugins? - maven

When I use version range for dependencies, it works fine but the same range for plugins fails.
So I have my own plugin, say:
<dependencies>
<dependency>
<groupId>com.mytest</groupId>
<artifactId>mytest-maven-plugin</artifactId>
<version>[1.0.0, 2.0.0)</version>
</dependency>
</dependencies>
This works like a charm, however, the following won't work:
<build>
<plugins>
<plugin>
<groupId>com.mytest</groupId>
<artifactId>mytest-maven-plugin</artifactId>
<version>[1.0.0, 2.0.0)</version>
</plugin>
</plugins>
</build>
And I get error saying could not find prefix "mytest". If I change the version in plugin section to 1.0.1, things are fine. I was wondering if ranges won't work for plugins or I am missing something here?

Related

Maven Versions Plugin - Exclude Major Version With Suffix

I am implementing the Maven versions plugin to manage our dependencies, but am having trouble excluding the next Spring major release due to the ".RELEASE" suffix.
Here's a snippet of my pom.xml:
<properties>
<spring.version>4.2.0.RELEASE</spring.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>[${spring.version},5.0.0.RELEASE)]</version>
<dependency>
</dependencies>
What I am trying to do is update to the latest 4.X.X (4.3.something) WITHOUT allowing the 5.0 series which could introduce breaking changes. Unfortunately, due to the suffix, it ignores the ")" which is supposed to ignore the 5.0.0 releases.
I do not currently have an externalized rules XML file (getting to it).
Can anyone assist?
Edit: I am using the following command to update:
mvn versions:use-latest-releases
Edit 2: Below is my configuration for the maven plugin:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>versions-maven-plugin</artifactId>
<version>2.7</version>
<configuration>
<allowIncrementalUpdates>true</allowIncrementalUpdates>
<allowMinorUpdates>true</allowMinorUpdates>
<allowMajorUpdates>false</allowMajorUpdates>
<allowSnapshots>false</allowSnapshots>
</configuration>
</plugin>

Spring Boot fails to run maven-surefire-plugin ClassNotFoundException org.apache.maven.surefire.booter.ForkedBooter

Running maven (3.5.2) build of a Spring Boot 2.0.2.RELEASE applicaton (generated by web initialiser with web dependencies) fails executing the maven-surefire-plugin saying just:
Error: Could not find or load main class
org.apache.maven.surefire.booter.ForkedBooter
Caused by: java.lang.ClassNotFoundException: org.apache.maven.surefire.booter.ForkedBooter
Why is this happening? Is it a problem in boot + surefire integration = a bug?
For reference, the dependencies that seem relevant are:
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.0.2.RELEASE</version>
<relativePath/>
</parent>
...
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
...
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
...
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
Workaround for the issue was to override Spring Boot's maven-surefire-plugin definition and set useSystemClassLoader to false. Read Surefire docs for more details
<build>
<plugins>
...
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<useSystemClassLoader>false</useSystemClassLoader>
</configuration>
</plugin>
</plugins>
</build>
The <useSystemClassLoader>false</useSystemClassLoader> solution provideded by jediz did allow my surefire tests to run, but broke class loading in some of my Spring Boot integration tests.
The following maven-surefire-plugin configuration worked for me:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<argLine>-Djdk.net.URLClassPath.disableClassPathURLCheck=true</argLine>
</configuration>
</plugin>
This is due to a known bug in the Maven Surefire plugin. It was fixed in version 3.0.0-M1, which was released in November 2018. So the simplest and most reliable fix is to upgrade which version of the plugin you use.
Updating the maven-surefire-plugin from 2.12.4 to 3.0.0-M1 worked for me. The project did not explicitly use the plugin, so I had to add a new plugin dependency.
<plugins>
...
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0-M1</version>
</plugin>
...
</plugins>
To me, the solution was to run mvn as
_JAVA_OPTIONS=-Djdk.net.URLClassPath.disableClassPathURLCheck=true mvn clean compile package
Other ideas (giving the system property to the maven argument list, different changes in pom.xml, settings.xml) did not work.
Despite that it didn't contain the exact solution, also this answer was very helpful for me to make it clear, that it is an unfortunate cooperation of two independent, alone harmless bugs in the Ubuntu JDK and the Maven Surefire Plugin.
Recent Debian (buster) with the same JDK and Maven versions doesn't seem affected by the problem, but Ubuntu (xenial) did.
The exact solution is coming from this answer.
Update from the future: with Debian Buster is alles okay and this workaround is not needed any more.
I was able to remove the maven-surefire-plugin from my POM after adding this to the top of my POM (inside the <project> node)
<prerequisites>
<maven>3.6.3</maven>
</prerequisites>
Why do I think this is the right answer?
It specifies the version of Maven that Maven recommends using: https://maven.apache.org/download.cgi
when you run mvn versions:display-plugin-updates it shows that it's taking the maven-surefire-plugin 3.0.0-M3 from super-pom, which so far seems to have this issue fixed.
You don't have to manage individual plugin versions independently going forward. Just your minimum maven version which controls the super-pom version.
Adding this to the maven-surefire-plugin I resolved the problem:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<forkCount>0</forkCount>
</configuration>
</plugin>

testng:jar:5.14.3 is invalid

When I run the selenium test cases using maven and it displays warning message: [WARNING] The POM for org.testng:testng:jar:5.14.3 is invalid, transitive dependencies (if any) will not be available, enable debug logging for more details
anyone knows?
Use the latest version of TestNG and your problem will be resolved.
If you are using maven, try putting following dependency in pom.xml.
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>6.9.10</version>
</dependency>
Updating the surefire plugin version in pom.xml might resolve you problem.
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.20.1</version>
</plugin>
</plugins>
</pluginManagement>
</build>
This resolved my errors:
Select Project --> right click and go to Properties --> select TestNG--> select Maven - select checkbox for 'Enable project specific settings'.

Intellij + springboot + maven + spring-loaded

I have an issue where debugging stops working in Intellij, when applying Spring-loaded as a dependency to the maven plugin.
Situation 1 (working):
Using a autogenerated spring-boot maven (pom.xml) file with a declared "Spring-boot-maven-plugin" I can debug my my app using the debug-maven command in intellij. The pom file looks like this:
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
Situation 2 (not working):
Following the guide lines here: spring-boot-hot-swapping one should add a dependency for spring-loaded, to make use of spring-loaded. The pom file now looks like:
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<dependencies>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>springloaded</artifactId>
<version>1.2.3.RELEASE</version>
</dependency>
</dependencies>
</plugin>
</plugins>
</build>
Debugging the same run-configuration as before does not work. The break-points simply never turns into a "checkmark" and the code never suspends. Code is now hotswapping as one would expect... If I remove the plugin-dependency again, debugging starts working again...
Please help me make situation two work!
IntelliJ 14.1.3 Ultimate, Java 7, Spring boot 1.2.4, Spring loaded 1.2.3
Since it seems there is no one with an answer to this (nor in IntelliJ forums) i've created an issue:
https://youtrack.jetbrains.com/issue/IDEA-142078
Did you try with spring-devtools (since 1.2.3) ? Use this dependency :
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
</dependency>
There is already a ticket here, it seams the same issue.

flexmojos ignoring configuration?

I am trying to build out a SWC file from a Flex library, and no matter what I do, flexmojos (3.6.1) seems to build a "config.xml" file in the bin/classes folder that is empty, and uses that for configuration, completely ignoring everything I put into the plugin > configuration element. I've tried it running command line, through m2e, and through Jenkins and I get the same problem every time. I'm stuck and I don't know what I'm doing wrong.
Here is the build portion of my POM.
<sourceDirectory>${basedir}/src</sourceDirectory>
<directory>${basedir}/bin</directory>
<plugins>
<plugin>
<groupId>org.sonatype.flexmojos</groupId>
<artifactId>flexmojos-maven-plugin</artifactId>
<version>3.6.1</version>
<extensions>true</extensions>
<dependencies>
<dependency>
<groupId>com.adobe.flex</groupId>
<artifactId>compiler</artifactId>
<version>${flex.version}</version>
<type>pom</type>
</dependency>
</dependencies>
<configuration>
<computeDigest>false</computeDigest>
<allowSourcePathOverlap>true</allowSourcePathOverlap>
<debug>false</debug>
<warnings>
<no-constructor>false</no-constructor>
</warnings>
</configuration>
</plugin>
</plugins>
Turns out I was running an older compile-swc target. When I flipped over to the new target I was fine. the m2e Eclipse plugin did not provide me the choice to select the latest target in their build configuration settings.

Resources