Adding properties to manifest file with spring boot - manifest

I want to add SplashScreen-Image: <image name> to the manifest file.
How do I do this with Spring Boot's Maven Plugin? If this is not possible, how do I create a single executable jar using maven with additional properties?

The answer was kinda obvious in hindsight. Spring-Boot's maven plugin rewrites the original manifest file so using the maven jar plugin the manifest can be written as normal. Like this:
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<configuration>
<archive>
<manifestEntries>
<splashscreen-image>${image.name}</splashscreen-image>
</manifestEntries>
</archive>
</configuration>
</plugin>
</plugins>
</build>

Related

fabric8 maven plugin configuration with image running Java > 8

I am using fabric8 maven plugin to deploy a vertx application into Openshift. My application is running with Java 11.
However, by default, the fabric8 maven plugin uses a Java 8 Docker image to create my vertx application image.
How is it possible to configure fabric8 maven plugin to use a Java 11 image ? Does it provide other images for Java > 8 ?
I fixed it for my Spring Boot application by adding from configuration to the generator. For vert.x the solution could look like this:
<plugin>
<groupId>io.fabric8</groupId>
<artifactId>fabric8-maven-plugin</artifactId>
<version>3.5.42</version>
<configuration>
<generator>
<config>
<vertx>
<from>fabric8/s2i-java:3.0-java11</from>
</vertx>
</config>
</generator>
</configuration>
</plugin>
Which tags are available for the s2i image can be looked up at the Docker Hub page: https://hub.docker.com/r/fabric8/s2i-java/tags
for me this solution from above didn't help but thanks of that! I've found out that I've to declare image in my profile definition. I'm running my openshift build like this: mvn clean fabric8:deploy -P openshift
What help me a lot was adding this to profile:
<properties>
<fabric8.generator.fromMode>docker</fabric8.generator.fromMode>
<fabric8.generator.from>fabric8/s2i-java:3.0-java11</fabric8.generator.from>
</properties>
Below part of my pom.xml have a look profile definition
<properties>
...
<java.version>11</java.version>
<maven.compiler.plugin.version>3.8.0</maven.compiler.plugin.version>
<fabric8-maven-plugin.version>4.4.1</fabric8-maven-plugin.version>
</properties>
<dependencies>
...
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>${spring.boot.version}</version>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>${maven.compiler.plugin.version}</version>
<configuration>
<release>${java.version}</release>
</configuration>
</plugin>
</plugins>
</build>
<profiles>
<profile>
<id>openshift</id>
<properties>
<fabric8.generator.fromMode>docker</fabric8.generator.fromMode>
<fabric8.generator.from>fabric8/s2i-java:3.0-java11</fabric8.generator.from>
</properties>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-kubernetes-dependencies</artifactId>
<version>0.3.0.RELEASE</version>
<type>pom</type>
<scope>import</scope>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>Finchley.SR2</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-kubernetes-config</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>io.fabric8</groupId>
<artifactId>fabric8-maven-plugin</artifactId>
<version>${fabric8-maven-plugin.version}</version>
<executions>
<execution>
<goals>
<goal>resource</goal>
<goal>build</goal>
</goals>
</execution>
</executions>
<configuration>
<enricher>
<config>
<f8-healthcheck-vertx>
<readiness>
<path>/actuator/health</path>
</readiness>
<liveness>
<path>/actuator/health</path>
</liveness>
</f8-healthcheck-vertx>
</config>
</enricher>
</configuration>
</plugin>
</plugins>
</build>
</profile>
</profiles>

Unable to suppress excessive logs from scalatest-maven-plugin

Background
I am facing excessive logging from default Logger when I run scala tests from maven because it is not picking up the logback.xml on the classpath with the correct logging definitions
So my maven config is fairly generic (as per scalatest-maven-plugin docs)
Looks like this
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.7</version>
<configuration>
<skipTests>true</skipTests>
</configuration>
</plugin>
<!-- enable scalatest -->
<plugin>
<groupId>org.scalatest</groupId>
<artifactId>scalatest-maven-plugin</artifactId>
<version>1.0</version>
<configuration>
<reportsDirectory>${project.build.directory}/surefire-reports</reportsDirectory>
<junitxml>.</junitxml>
<filereports>MyProj_TestSuite.txt</filereports>
<forkMode>never</forkMode>
</configuration>
<executions>
<execution>
<id>test</id>
<goals>
<goal>test</goal>
</goals>
</execution>
</executions>
</plugin>
I have a logback.xml in my src/main/resources which gets copied over to target/classes
Things I tried so far
Have spent a whole day to figure out why this is not being picked up -- using the following configuration optional entries
<runpath>
${project.basedir}/target/classes
</runpath>
<systemProperties>
<logback.configurationFile> ${project.basedir}/src/main/resources/logback.xml</logback.configurationFile>
</systemProperties>
<argLine>
-Dlogback.configurationFile=src/main/resources/logback.xml
</argLine>
If I run it like this (from command line) from ${project.basedir}
mvn test -Dlogback.configurationFile=./src/test/resources/logback.xml
it works
I have looked at similar issues on stack and even tried adding this
<build>
<testResources>
<testResource>
<directory>${project.basedir}/target/classes</directory>
</testResource>
<testResource>
<directory>${project.basedir}/src/test/resources</directory>
</testResource>
</testResources>
</build>
This did not work - I think it is because I am using scala-maven-test plugin which has its own configuration block.
Any help on how to do this from inside the pom.xml will be much appreciated.
Try to have /src/test/resources/logback-test.xml logback configuration file.
It works for me with scalatest-maven-plugin of 2.0.2 version.

maven-jaxb2-plugin ignoring configuration

I'm using maven 3.3.9 and the maven-jaxb2-plugin 0.13.1. But when I try to generate the Java classes, the plugin is not finding my XSD-file.
My pom looks like this:
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.jvnet.jaxb2.maven2</groupId>
<artifactId>maven-jaxb2-plugin</artifactId>
<version>0.13.1</version>
<executions>
<execution>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<schemaDirectory>src/main/resources/schemas</schemaDirectory>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</pluginManagement>
</build>
Everytime I'm executing the goal, I get this message:
[WARNING] No schemas to compile. Skipping XJC execution.
The directory exists under the resources folder, and the XSD is placed there. I have no other pom-files in play.
Any help would be very much appreciated
In case anyone else will hit this. I had a similar issue: the configuration was not picked up by the plugin. I made it work by moving configuration section under plugin declaration instead of execution.
Here's how the working configuration looked like for me (I removed the upper-level elements since they do not matter):
<plugin>
<groupId>org.jvnet.jaxb2.maven2</groupId>
<artifactId>maven-jaxb2-plugin</artifactId>
<version>0.15.1</version>
<configuration>
<schemaDirectory>src/main/resources/custom-schemas</schemaDirectory>
</configuration>
<executions>
<execution>
<id>generate</id>
<goals>
<goal>generate</goal>
</goals>
</execution>
/executions>
</plugin>
Author of maven-jaxb2-plugin here.
Somehow I have a feeling that you're omitting important details. This does not not add up. This is a very basic configuration setting, I'm curious how it can't work.
You only post the pluginManagement part of your pom.xml. If you have just this, it should not work at all as it is just and only a declaration of configuration, not actual usage of the plugin. You need plugins/plugin to actually apply the plugin:
<project ...>
...
<build>
<plugins>
...
<plugin>
<groupId>org.jvnet.jaxb2.maven2</groupId>
<artifactId>maven-jaxb2-plugin</artifactId>
<version>...</version>
<executions>
<execution>
<goals>
<goal>generate</goal>
</goals>
</execution>
</executions>
</plugin>
...
</plugins>
</build>
...
</project>
To analyze the problem, run mvn -X clean generate-sources or mvn -X clean install and check the applied configuration (it will be logged). Post the log here.
If this does not help, send me a PR of a minimal reproducing project under https://github.com/highsource/maven-jaxb2-plugin-support/s/schemaDirectory, I'll take a look.

IntelliJ Error when running unit test: Could not find or load main class ${surefireArgLine}

I get the following error when running Unit tests in IntelliJ:
Error: Could not find or load main class ${surefireArgLine}.
I am using maven and in pom.xml I have:
<properties>
...
<surefire.argLine />
</properties>
<build>
<plugins>
<plugin>
<groupId>com.mysema.maven</groupId>
<artifactId>apt-maven-plugin</artifactId>
<version>1.1.1</version>
<executions>
<execution>
<goals>
<goal>process</goal>
</goals>
<configuration>
<outputDirectory>target/generated-sources/java</outputDirectory>
<processor>com.mysema.query.apt.jpa.JPAAnnotationProcessor</processor>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.17</version>
<configuration>
<!--Sets the VM argument line used when unit tests are run.-->
<argLine>${surefire.argLine}</argLine>
</configuration>
</plugin>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.7.1.201405082137</version>
<executions>
<!--
Prepares the property pointing to the JaCoCo runtime agent which
is passed as VM argument when Maven the Surefire plugin is executed.
-->
<execution>
<id>pre-unit-test</id>
<goals>
<goal>prepare-agent</goal>
</goals>
<configuration>
<!--Sets the path to the file which contains the execution data.-->
<destFile>${project.build.directory}/coverage-reports/jacoco-ut.exec</destFile>
<!--
Sets the name of the property containing the settings
for JaCoCo runtime agent.
-->
<propertyName>surefireArgLine</propertyName>
</configuration>
</execution>
...
Did anyone have similiar problem? How to set value for surefireArgLine?
I had the same problem and i think i found the solution on the vertx-issue tracker.
In short you have to configure your IntelliJ Maven (surefire plugin) integration to behave differently.
This works for me in IntelliJ 14.1.6 with mvn 3.3.9
Preferences -> Build,Execution,Deployment -> Build Tools -> Maven -> Running Tests
For IntelliJ 2019 and above
Settings-> Build,Execution,Deployment -> Build Tools -> Maven -> Running Tests
Uncheck argLine
I was able to fix this error in Netbeans by changing the surefire-plugin version to 2.10 and removing
<argLine>-Xmx1024m -XX:MaxPermSize=256m ${argLine}</argLine>
from the maven-surefire-plugin configuration. Instead i have created a property argLine that is picked automatically by surefire.
<properties>
<argLine>-Xmx1024m -XX:MaxPermSize=256m</argLine>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.10</version>
</plugin>
Now, i can run and debug single files and test methods. And Code Coverage is working as expected.
Update of pom.xml solved my problem.
<argLine>${surefire.argLine}</argLine>
Complete plugin info in pom.xml
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.18.1</version>
<configuration>
<parallel>classes</parallel>
<threadCount>10</threadCount>
<workingDirectory>${project.build.directory}</workingDirectory>
<jvm>${env.JDK1_8_HOME}\bin\java</jvm>
<argLine>${surefire.argLine}</argLine>
</configuration>
<dependencies>
<dependency>
<groupId>org.apache.maven.surefire</groupId>
<artifactId>surefire-junit4</artifactId>
<version>2.18.1</version>
</dependency>
</dependencies>
</plugin> -->
Was looking for this and found this project "fix" it in this thread
Basically define your jacocoArgLine var name as empty project property. Then in surefire configuration use #{jacocoArgLine} instead of dollar prefix.
I found out that I have to run my test case from maven with
mvn -Dtest=TestCircle test
not directly from IDE.
For a more permanent fix for every new project add the following to your IntelliJ IDEA Custom VM Options:
Help > Edit Custom VM options
Add: -Didea.maven.surefire.disable.argLine=true
This will deactivate surefire for all new projects you open.

maven use a different directory for site source files than src/site

I need to configure where my Maven 2 project's site files are located, by default they are src/site/, I'd like to point them to src-documentation/site, how would I override Maven's default conventin?
As maven-site-plugin documentation says you need to configure plugin
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-site-plugin</artifactId>
<version>2.0</version>
<configuration>
<siteDirectory>${basedir}/src-documentation/site</siteDirectory>
</configuration>
</plugin>
</plugins>