Spring boot META-INF/build-info.properties not in artifact - java

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

Related

How to avoid install / deploy spring boot fat jar to maven repo

We are using the spring-boot-maven-plugin's repackage task for packaging fat-jar (sample pom.xml below), and tried the <attach>false</attach>, but seems the fat-jar will be install / deployed anyway.
Currently, we configured maven-{install,deploy}-plugin's <skip>true</skip> to work around this issue, but not sure how to use boot plugin's <attach> or other ways to fix this.
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>2.2.4.RELEASE</version>
<executions>
<execution>
<id>repackage</id>
<goals>
<goal>repackage</goal>
</goals>
<configuration>
<attach>false</attach>
</configuration>
</execution>
</executions>
</plugin>
Thanks
You have to configure it correctly like this:
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>2.2.4.RELEASE</version>
<executions>
<execution>
<id>repackage</id>
<goals>
<goal>repackage</goal>
</goals>
<configuration>
<attach>false</attach>
</configuration>
</execution>
</executions>
</plugin>

How to package spring-boot to jar with local jar using maven

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>

Why is my Maven project packaging test files?

I have a Maven project which I'm trying to package, but I've noticed that all my Java test classes (but none of my Scala test classes) and generated Avro test classes are ending up in the jar.
Folder structure looks fine:
I also noticed that if I add junit as a dependency with <scope>test</scope>, my tests won't compile as it can't find the junit classes, so it looks like Maven is treating all my code including tests as being part of main.
Pom:
<?xml version="1.0" encoding="UTF-8"?>
<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.me</groupId>
<artifactId>proj</artifactId>
<version>1.0.0</version>
<properties>
<log4j.version>2.8.1</log4j.version>
</properties>
<dependencies>
...
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.scalatest</groupId>
<artifactId>scalatest-maven-plugin</artifactId>
<executions>
<execution>
<id>test</id>
<goals>
<goal>test</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>net.alchim31.maven</groupId>
<artifactId>scala-maven-plugin</artifactId>
<version>3.2.1</version>
<executions>
<execution>
<id>scala-compile-first</id>
<phase>process-resources</phase>
<goals>
<goal>add-source</goal>
<goal>compile</goal>
</goals>
</execution>
<execution>
<id>scala-test-compile</id>
<phase>process-test-resources</phase>
<goals>
<goal>testCompile</goal>
</goals>
</execution>
</executions>
<configuration>
<scalaVersion>2.11.8</scalaVersion>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.avro</groupId>
<artifactId>avro-maven-plugin</artifactId>
<version>1.8.1</version>
<executions>
<execution>
<phase>generate-sources</phase>
<goals>
<goal>schema</goal>
</goals>
<configuration>
<sourceDirectory>${project.basedir}/src/test/resources/</sourceDirectory>
<outputDirectory>${project.basedir}/src/test/java</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.6.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
<executions>
<execution>
<phase>compile</phase>
<goals>
<goal>compile</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<executions>
<execution>
<id>attach-sources</id>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
Figured it out.
The issue was with the avro-maven-plugin.
It's configuration had sourceDirectory and outputDirectory, both of which had test source paths.
<configuration>
<sourceDirectory>${project.basedir}/src/test/resources/</sourceDirectory>
<outputDirectory>${project.basedir}/src/test/java</outputDirectory>
</configuration>
Apparently these were interfering with the compiler plugin which thought that these directories were main source directories and compiled them along with the rest of the main classes. This also explains why my tests were failing to compile when the junit dependency was given a test scope.
The solution was to use testSourceDirectory and testOutputDirectory instead:
<configuration>
<testSourceDirectory>${project.basedir}/src/test/resources/</testSourceDirectory>
<testOutputDirectory>${project.basedir}/src/test/java</testOutputDirectory>
</configuration>
mvn clean install -Dmaven.test.skip=true -X

Findbugs plugin configuration in maven pom.xml

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>

How can I add a Maven exec task to execute on `mvn test`

I have the following exec task in my pom:
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.1</version>
<executions>
<execution>
<goals>
<goal>exec</goal>
</goals>
</execution>
</executions>
<configuration>
<executable>${project.basedir}/src/test/javascript/EnvJasmine/bin/run_all_tests.sh</executable>
</configuration>
</plugin>
</plugins>
This works great when I run
mvn exec:exec
But I also want it to run when I execute
mvn test
Can anyone help me here?
Got it! You add <phase> to the execution!
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.1</version>
<executions>
<execution>
<id>Jasmine Tests</id>
<phase>test</phase>
<goals>
<goal>exec</goal>
</goals>
</execution>
</executions>
<configuration>
<executable>${project.basedir}/src/test/javascript/EnvJasmine/bin/run_all_tests.sh</executable>
</configuration>
</plugin>
</plugins>
Woohoo!

Categories

Resources