My goal is to execute findbugs on a maven project -> generate xml -> convert xml to html & finally fail build if there are HIGH priority FindBugs warnings. Below is the plugin configuration configuration in pom.xml I have configured
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>findbugs-maven-plugin</artifactId>
<version>3.0.3</version>
<executions>
<execution>
<id>noFailOnError</id>
<phase>verify</phase>
<goals>
<goal>check</goal>
</goals>
<configuration>
<failOnError>false</failOnError>
<xmlOutput>true</xmlOutput>
<findbugsXmlOutputDirectory>${project.build.directory}/findbugs</findbugsXmlOutputDirectory>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>xml-maven-plugin</artifactId>
<version>1.0</version>
<executions>
<execution>
<phase>verify</phase>
<goals>
<goal>transform</goal>
</goals>
</execution>
</executions>
<configuration>
<transformationSets>
<transformationSet>
<dir>${project.build.directory}/findbugs</dir>
<outputDir>${project.build.directory}/findbugs</outputDir>
<stylesheet>fancy-hist.xsl</stylesheet>
<!--<stylesheet>default.xsl</stylesheet> -->
<!--<stylesheet>plain.xsl</stylesheet> -->
<!--<stylesheet>fancy.xsl</stylesheet> -->
<!--<stylesheet>summary.xsl</stylesheet> -->
<fileMappers>
<fileMapper
implementation="org.codehaus.plexus.components.io.filemappers.FileExtensionMapper">
<targetExtension>.html</targetExtension>
</fileMapper>
</fileMappers>
</transformationSet>
</transformationSets>
</configuration>
<dependencies>
<dependency>
<groupId>com.google.code.findbugs</groupId>
<artifactId>findbugs</artifactId>
<version>2.0.0</version>
</dependency>
</dependencies>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>findbugs-maven-plugin</artifactId>
<version>3.0.3</version>
<executions>
<execution>
<id>failing-on-high</id>
<phase>verify</phase>
<goals>
<goal>findbugs</goal>
</goals>
<configuration>
<failOnError>true</failOnError>
</configuration>
</execution>
</executions>
</plugin>
My problem is that html transformation is not happening stating that
[WARNING] No files found for transformation by stylesheet fancy-hist.xsl
Can the pom.xml correctness be verified & also can someone help me with the reason on why html tansformation is not happening ?
The issue with the above plugin configuration is that failing-on-high is configured during the verify phase rather than install phase. So in case of build error in verify phase, no output xml is generated because of which the output xml was not found. This was fixed by changing it to install
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>findbugs-maven-plugin</artifactId>
<version>3.0.3</version>
<executions>
<execution>
<id>failing-on-high</id>
<phase>install</phase>
<goals>
<goal>findbugs</goal>
</goals>
<configuration>
<failOnError>true</failOnError>
</configuration>
</execution>
</executions>
</plugin>
Related
I have to exclude from Versions Maven Plugin command (use-latest-versions), a dependency that I don't want to automatically update.
Here is the doc:
https://www.mojohaus.org/versions-maven-plugin/use-latest-releases-mojo.html#excludes
This is how I have implemented the excludes optional parameter in the pom.xml file:
...
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>versions-maven-plugin</artifactId>
<version>2.8.1</version>
<executions>
<execution>
<phase>validate</phase>
<goals>
<goal>use-latest-versions</goal>
</goals>
<configuration>
<excludes>["org.mongodb:mongodb-driver-sync:jar:4.2.3"]</excludes>
</configuration>
</execution>
</executions>
</plugin>
...
Anyway during maven validate, the mongodb dependency is updated, ignoring the excludes parameters. Where is the mistake?
EDIT:
Now it works. Below the correct configuration:
...
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>versions-maven-plugin</artifactId>
<version>2.8.1</version>
<executions>
<execution>
<phase>validate</phase>
<goals>
<goal>use-latest-versions</goal>
</goals>
<configuration>
<excludes>
<exclude>org.mongodb:mongodb-driver-sync:jar:4.2.3</exclude>
</excludes>
</configuration>
</execution>
</executions>
</plugin>
...
My goal is to generate Spring Boot REST Client using OpenAPI 3.0.
I would like to first generate the OpenAPI specification file (springdoc-openapi-maven-plugin) of my API and then generate the client code from this file (swagger-codegen-maven-plugin) using Maven.
My problem is that swagger-codegen-maven-plugin is executed before springdoc-openapi-maven-plugin. So, the output file generated by springdoc-openapi-maven-plugin does not exist when swagger-codegen-maven-plugin executes.
How to execute springdoc-openapi-maven-plugin before swagger-codegen-maven-plugin given the following Maven build plugins configuration?
My Maven build plugin configuration:
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>2.4.1</version>
<executions>
<execution>
<id>pre-integration-test</id>
<goals>
<goal>start</goal>
</goals>
</execution>
<execution>
<id>post-integration-test</id>
<goals>
<goal>stop</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.springdoc</groupId>
<artifactId>springdoc-openapi-maven-plugin</artifactId>
<version>1.1</version>
<executions>
<execution>
<id>integration-test</id>
<goals>
<goal>generate</goal>
</goals>
</execution>
</executions>
<configuration>
<apiDocsUrl>myServerUrl:myPort/v3/api-docs</apiDocsUrl>
<outputFileName>openApiFile.json</outputFileName>
<outputDir>${project.basedir}/src/main/resources</outputDir>
<skip>false</skip>
</configuration>
</plugin>
<plugin>
<groupId>io.swagger.codegen.v3</groupId>
<artifactId>swagger-codegen-maven-plugin</artifactId>
<version>3.0.24</version>
<executions>
<execution>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<inputSpec>${project.basedir}/src/main/resources/openApiFile.json</inputSpec>
<language>typescript-angular</language>
<configOptions>
<sourceFolder>src/gen/java/main</sourceFolder>
</configOptions>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
The issue was that springdoc-openapi-maven-plugin is executed during integration-test phase while swagger-codegen-maven-plugin default phase is generate-sources which is executed before integration-test in the build lifecycle.
I just specified a phase for swagger-codegen-maven-plugin which is after integration-test: <phase>post-integration-test</phase>.
I would like to access my commit info in /info. Thing is, it works in IDE but there seems to be a problem while packaging the artifact, the file META-INF/build-info.properties is not packaged into jar! Any hint why?
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>build-info</goal>
</goals>
<phase>package</phase>
</execution>
</executions>
<configuration>
<additionalProperties>
<number>${buildNumber}</number>
<job>${buildJob}</job>
</additionalProperties>
</configuration>
</plugin>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>${spring-boot.version}</version>
<configuration>
<mainClass>${start-class}</mainClass>
<executable>true</executable>
</configuration>
<executions>
<execution>
<goals>
<goal>build-info</goal>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>
Remove <phase>package</phase> from your execution and now do a mvn clean install. It should generate META-INF/build-info.properties file
I have a jar in my system, and I want to package it into jar application using maven, my dependency and plugin as below:
<dependency>
<groupId>org.wltea</groupId>
<artifactId>IKAnalyzer</artifactId>
<version>3.2.3</version>
<scope>system</scope>
<systemPath>${project.basedir}/src/main/BOOT-INF/lib/IKAnalyzer3.2.3Stable.jar</systemPath>
</dependency>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
<configuration>
<mainClass>gpdi.MyApp</mainClass>
</configuration>
</execution>
</executions>
</plugin>
I also try maven-dependency-plugin but did'nt work when packaging jar file.
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<id>copy-dependencies</id>
<phase>compile</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<outputDirectory>${project.build.directory}/${project.build.finalName}/BOOT-INF/lib</outputDirectory>
<includeScope>system</includeScope>
</configuration>
</execution>
</executions>
</plugin>
Add the below plugin and clean your project :
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-install-plugin</artifactId>
<executions>
<execution>
<id>install-Transformation lib</id>
<phase>clean</phase>
<configuration>
<file>${basedir}/file/path/jarname.jar</file>
<repositoryLayout>default</repositoryLayout>
<groupId>org.wltea</groupId>
<artifactId>IKAnalyzer</artifactId>
<version>3.2.3</version>
<packaging>jar</packaging>
<generatePom>true</generatePom>
</configuration>
<goals>
<goal>install-file</goal>
</goals>
</execution>
</executions>
</plugin>
Once you clean the project. Comment scope and systempath like below then build and install :
<dependency>
<groupId>org.wltea</groupId>
<artifactId>IKAnalyzer</artifactId>
<version>3.2.3</version>
<!--scope>system</scope>
<systemPath>${project.basedir}/src/main/BOOT-INF/lib/IKAnalyzer3.2.3Stable.jar</systemPath-->
</dependency>
Here is my pom.xml file and the error i got when building
Error:
Failed to execute goal org.apache.maven.plugins:maven-assembly-plugin:2.2-beta-5:single (default-cli) on project load-xml-to-s3: Error reading assemblies: No assembly descriptors found.
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.tte.s3.load</groupId>
<artifactId>load-xml-to-s3</artifactId>
<version>1.0</version>
<name>load-xml-to-s3</name>
<build>
<plugins>
<!-- TOBE USED LATER - DO NOT DELETE. - KC <plugin> <groupId>com.google.code.maven-replacer-plugin</groupId>
<artifactId>replacer</artifactId> <version>1.5.3</version> <executions> <execution>
<phase>prepare-package</phase> <goals> <goal>replace</goal> </goals> </execution>
</executions> <configuration> <file>target/classes/somefile.txt</file> <replacements>
<replacement> <token>SOME TOKEN</token> <value>SOME VALUE</value> </replacement>
</replacements> </configuration> </plugin> -->
<plugin>
<groupId>com.jolira</groupId>
<artifactId>onejar-maven-plugin</artifactId>
<version>1.4.4</version>
<executions>
<execution>
<configuration>
<mainClass>com.tte.s3.load.driver.Driver</mainClass>
</configuration>
<goals>
<goal>one-jar</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<executions>
<execution>
<id>make-assembly</id>
<phase>assembly</phase>
<goals>
<goal>single</goal>
</goals>
<configuration>
<descriptors>
<descriptor>distribution.xml</descriptor>
</descriptors>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</build>
</project>
The descriptors attribute of the maven-assembly-plugin expects a path starting from the base directory of your project. For example, if the file is located inside src/assembly/distribution.xml, this is the path you should specify.
There is also a problem in the phase you bound the plugin to. Phase assembly does not exist, you should use <phase>package</phase> instead.
As a side-node, you are using an old version of the plugin (2.2-beta-5). Consider using the latest version instead, which is 2.6.
Sample configuration:
<plugin>
<!-- no need to specify the groupId, it defaults to "org.apache.maven.plugins" -->
<artifactId>maven-assembly-plugin</artifactId>
<version>2.6</version> <!-- explicit version is safer for build consistency than implicit -->
<executions>
<execution>
<id>make-assembly</id>
<phase>package</phase> <!-- bind the execution to the "package" phase -->
<goals>
<goal>single</goal>
</goals>
<configuration>
<descriptors>
<descriptor>src/assembly/distribution.xml</descriptor> <!-- use the path to the file starting from base directory -->
</descriptors>
</configuration>
</execution>
</executions>
</plugin>
Running Maven with mvn clean install will invoke the plugin correctly in the package phase.