How to migrate maven plugins form maven to gradle - java

I am migrating my spring boot project from maven to gradle. I have done dependencies migration, but have problems with plugin migration. Need an assistanse. Also if there any real example with comparing maven and gradle plugin will be appreciated. I have already done stuffs like gradle init and so I need something new. Here is my code:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-pmd-plugin</artifactId>
<version>3.13.0</version>
<configuration>
<linkXRef>false</linkXRef>
<rulesets>
<ruleset>/config/setting/setting.xml</ruleset>
</rulesets>
</configuration>
</plugin>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.8.5</version>
<configuration>
<destFile>${sonar.jacoco.reportPath}</destFile>
<append>true</append>
</configuration>
<executions>
<execution>
<id>report-sonar</id>
<phase>verify</phase>
<goals>
<goal>report-sonar</goal>
</goals>
</execution>
</executions>
</plugin>
2 plugins I am struggling with. If you could show me the migrations of this two, I think i will manage to do the others.

For both of your plugins there is a gradle plugin,too.
The docs look pretty promising.
https://docs.gradle.org/current/userguide/jacoco_plugin.html
https://docs.gradle.org/current/userguide/pmd_plugin.html

Related

Maven JavaDoc listed classes twice

I am using the javadoc maven plugin and it creates the correct javadoc package, but all classes are created twice.
Maven dependency:
<dependency>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>3.3.0</version>
</dependency>
My build code
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<executions>
<execution>
<id>attach-javadocs</id>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
Can anyone help me please, what am I missing here?
command usage for doc generation
mvn clean install -Dresources="FirstProject/example_API"
I noticed the same problem and came upon a solution after enabling debug on the maven-javadoc-plugin maven plugin and seeing what it's doing. Specifically setting the sourcepath as shown below fixed the double listing problem for me and I've tried this on multiple version of Corretto 8 as well as Temurin 8. All had the double listing problem because it's an issue with the javadoc tool itself but setting the sourcepath manually fixed it for me.
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>3.3.1</version>
<configuration>
<debug>true</debug>
<sourcepath>${basedir}/src/main/java</sourcepath>
</configuration>
<executions>
<execution>
<id>attach-javadocs</id>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>
There's a bug in recent versions of the Maven Javadoc Plugin. The bug is known as MJAVADOC-700. It is dead easy to reproduce.
Downgrading to version 3.2.0 of the plugin fixes the problem. Setting the sourcepath explicitly is an alternative fix.

Execution findbugs of goal org.codehaus.mojo:findbugs-maven-plugin:3.0.5:findbugs failed: Java returned: 1

Findbugs does not support jdk11, I have a project in which I have a dependency jar which uses findbugs.
https://github.com/gleclaire/findbugs-maven-plugin/issues/93
Although I don't have findbugs maven plugin in my project but due to the dependency jar, it still executes.
How can I stop it from executing, because it fails every time.
I tried with below, but doesn't work.
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>findbugs-maven-plugin</artifactId>
<version>${plugin.findbugs-maven-plugin.version}</version>
<configuration>
<excludeFilterFile>${project.basedir}/exclude-findbugs.xml</excludeFilterFile>
<failOnError>false</failOnError>
</configuration>
<executions>
<execution>
<goals>
<goal>findbugs</goal>
</goals>
<configuration>
<failOnError>false</failOnError>
<skip>true</skip>
</configuration>
</execution>
</executions>
</plugin>
Can someone please help me?
TIA
It worked by adding a skip tag as true. as below.
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>findbugs-maven-plugin</artifactId>
<version>${plugin.findbugs-maven-plugin.version}</version>
<configuration>
<excludeFilterFile>${project.basedir}/exclude-findbugs.xml</excludeFilterFile>
<skip>true</skip>
</configuration>
</plugin>

Mojo Codehaus Properties Plugin Alternatives

I am currently trying to work with Codehaus Mojo Properties. I only found out about it this morning.
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>properties-maven-plugin</artifactId>
<version>1.0.0</version>
</plugin>
So I cant say that I am an expert on it. But when trying to build a war file I keep getting:
Caused by: org.apache.maven.plugin.MojoFailureException: Circular property definition:
My plugin configuration is:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>properties-maven-plugin</artifactId>
<inherited>true</inherited>
<executions>
<execution>
<id>read-pal-properties</id>
<phase>initialize</phase>
<goals>
<goal>read-project-properties</goal>
</goals>
<configuration>
<files>
<file>${project.basedir}\src\main\resources\system.properties</file>
</files>
</configuration>
</execution>
</executions>
</plugin>
A property that fails is:
webserver.websphere=WebSphere:cell=${webserver.cell},node=${webserver.node},server=${webserver.server}
I googled a bit about it, and saw that this is a known bug. So just wanted to see if there are other plugins that do that same job.
https://github.com/mojohaus/properties-maven-plugin/issues/27
Any help would be appreciated.
If you still haven't found the answer yet after >2years, use the 1.0-alpha-2 version

Maven pom plugin not executing on build

I'm practicing Maven and I've hit a wall. I've installed the PlantUml plugin on IntelliJ and I'm trying to set it up so that it always generates a new image from the source file on compile time. I'm using this plugin to generate the image, and I've configured the pom.xml file as follows:
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>com.github.jeluard</groupId>
<artifactId>plantuml-maven-plugin</artifactId>
<version>1.2</version>
<executions>
<execution>
<id>GeneratePlantUml</id>
<phase>generate-resources</phase>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<outputDirectory>${basedir}/images</outputDirectory>
</configuration>
</execution>
</executions>
<configuration>
<sourceFiles>
<directory>${basedir}/plantuml</directory>
<includes>
<include>TestGeneratorDiagram.puml</include>
</includes>
</sourceFiles>
<outputDirectory>${basedir}/images</outputDirectory>
</configuration>
<dependencies>
<dependency>
<groupId>net.sourceforge.plantuml</groupId>
<artifactId>plantuml</artifactId>
<version>8031</version>
</dependency>
</dependencies>
</plugin>
<plugins>
</pluginManagement>
<build>
This works fine when I use a terminal command where I specify the goal:
mvn compile com.github.jeluard:plantuml-maven-plugin:generate
However, it doesn't work if I just write:
mvn compile
Which, as far as I know, should also work. I've tried setting the phase on compile but it didn't change anything. I've searched for hours now for a solution but I haven't found one. Does anyone know how I can force the plugin to generate a new image on compile time by configuring the pom?
You have put your configuration into pluginManagement. You needs to put it into plugins (outside pluginManagement).
The pluginManagement is just to override/specify configuration and version numbers.
Have a look at Maven: What is pluginManagement?
your plugin and your execution is configure à the "generate-resources" phase and not at the compile phase like you want.
See this link to more detail on phase.
change this:
<execution>
<id>GeneratePlantUml</id>
<phase>generate-resources</phase>
<goals>
<goal>generate</goal>
</goals>
to this
<execution>
<id>GeneratePlantUml</id>
<phase>compile</phase>
<goals>
<goal>generate</goal>
</goals>
It must works.

Converting maven project that uses plugins to a gradle project

I'm new with Gradle and confused to change maven code to gradle, I get code from ApacheKarafCookbook and want to use gradle as build tool. I tried use gradle init and its not working.
<build>
<plugins>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.7.0.201403182114</version>
<executions>
<execution>
<id>prepare-agent-integration</id>
<goals>
<goal>prepare-agent-integration</goal>
</goals>
<phase>pre-integration-test</phase>
<configuration>
<propertyName>jcoverage.command</propertyName>
<includes>
<include>com.packt.*</include>
</includes>
<append>true</append>
</configuration>
</execution>
<execution>
<id>report</id>
<goals>
<goal>report-integration</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
How do I change to gradle?
gradle init will not do auto conversion of maven plugins, phases and targets. You'll have to do that bit by hand. Here's some documentation on how to setup and use the gradle jacoco plugin.

Categories

Resources