Could not find goal 'build-image' in plugin org.springframework.boot:spring-boot-maven-plugin: - spring

I am trying to build a image from my spring-boot project.
This is my configuration for spring-boot maven plugin:
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<image>
<name>abc/xyz-${project.artifactId}:${project.version}</name>
</image>
<pullPolicy>IF_NOT_PRESENT</pullPolicy>
</configuration>
</plugin>
</plugins>
</build>
But while building the image "spring-boot:build-image" from Eclipse to build a image giving me following error:
Could not find goal 'build-image' in plugin
org.springframework.boot:spring-boot-maven-plugin:2.2.4.RELEASE among
available goals build-info, help, repackage, run, start, stop -> [Help
1]
Not sure what exactly the issue is.
Thanks,
Atul

Found the issue and also able to solved it.
The configuration needed :
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>2.4.2</version>
<configuration>
<image>
<name>abc/xyz-${project.artifactId}:${project.version}</name>
</image>
<pullPolicy>IF_NOT_PRESENT</pullPolicy>
</configuration>
</plugin>
</plugins>
</build>
Need to specify the version of sring-boot here. 2.4.2
Recently I was moved to version 2.4.2 spring boot version.
Thanks,
Atul

You need Spring Boot version 2.3.0.M1 or higher. The solution provided by #Atul above uses 2.4.2 so its a later version and has this feature.
For more information check this link

Related

tomcat8-maven-plugin ? (emphasis on the 8!)

Is there a version 8 (tomcat8) of the below?
<build>
<finalName>SampleServletFinalName</finalName>
<plugins>
<plugin>
<groupId>org.apache.tomcat.maven</groupId>
<artifactId>tomcat7-maven-plugin</artifactId>
<version>2.2</version>
</plugin>
</plugins>
</build>
and corresponding
mvn tomcat7:run
maven search does not reveal anything
https://search.maven.org/classic/#search%7Cga%7C1%7Cg%3A%22org.apache.tomcat.maven%22
Unfortunately, the plugin is not yet ready but you can find some workarounds here :
Tomcat 8 Maven Plugin for Java 8
Maybe the tomee-maven-plugin solves your problem as well:
<plugin>
<groupId>org.apache.tomee.maven</groupId>
<artifactId>tomee-maven-plugin</artifactId>
<version>7.1.1</version>
</plugin>
The difference here is, that you wont get a Tomcat, but TomEE. You can compare them by looking at this matrix.
(Version 7.1.1 wraps a Tomcat 8.5.41)

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>

using spring-boot-maven-plugin with exec classifier, but can't run the app from IDE anymore

I am working on Spring Boot 1.5.9 application, and I am generating a jar that contains a Spring Boot application, but that can also be imported as part of another project.
Therefore, I am using below config to generate 2 jars : the exec, and the regular lib ones.
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<classifier>exec</classifier>
</configuration>
</plugin>
However, now that I have this, I am not able to run the application from my IDE (Intellij) anymore, as it's not finding the application.yml.
I am sure there's a trick, but I can't find anything.. Any idea ?
I ended up using Maven profiles :
<profiles>
<profile>
<id>makeRelease</id>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<classifier>exec</classifier>
</configuration>
</plugin>
</plugins>
</build>
</profile>
</profiles>
When I make the release, I am calling this profile (maven with argument -P makeRelease) so that it generates the 2 jars.
The rest of the time, the regular behavior applies.

Installing and compiling Maven artifacts on Java 8

I have a project with a pom.xml that has the following <build> declaration:
<build>
<plugins>
<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>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
</plugins>
</build>
When I run mvn install on this project, it compiles the project, runs unit tests and publishes it to my local repo. I am trying to learn a little more about Maven here, and am having a tough time finding documentation/explanations on the following:
How am I able to run mvn install, if the POM doesn't declare it under build/plugins? Does maven-compiler-plugin include maven-install-plugin, if so, how could I have figured that out?
Most importantly: the value of build/plugins/plugin/configuration/source and .../target are both set to 1.8. If my machine has Java 8 on it, and I run mvn install on this project without any errors, does that guarantee that the project builds with Java 8? I'm looking at the docs for the Compiler Plugin and don't see those source/target configs listed anywhere.
First you should learn what the build life cycle is and how it works and how the plugins are bound to the life cycle by default.
Furthermore you should understand that in Maven every project inherits from the super pom file which is part of the maven distribution (the package you have downloaded). The super pom defines the default folder layout and some versions of plugins.
The question to define the maven-compiler-plugin as you did is to be very accurate simply wrong. You should have defined it like the following:
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.8</source>
<target>1.8</target>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>
This would overwrite the definition which is inherited by the super pom and changes it's configuration. In your case i would suggest to change the definition into this:
<project>
...
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.2</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>
..
</project>
The encoding should be set globally cause there are other plugins which use this definition like the maven-resources-plugin. The usage of the above property simplifies this, cause every plugin which has an option for encoding will use the default as defined in the property.
To be sure using the correct version of Java (your JDK on your machine) you have to use the maven-enforcer-plugin.
Apart from that please take a look onto the plugins page which shows the most up-to-date releases of the plugins.
As a good documentation i can recomment the Books on Maven but be aware they are written with Maven 2 in mind. So if something is not clear ask on users mailing list of here on SO.

findbugs maven plugin site vs check

I'm just trying to wrap my head around a couple of things.
If I have this in my masterpom:
<reporting>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>findbugs-maven-plugin</artifactId>
<version>2.5.2</version>
<configuration>
<failOnError>false</failOnError>
<threshold>High</threshold>
<effort>Default</effort>
<xmlOutput>true</xmlOutput>
<skip>${skipFindBugs}</skip>
<xmlOutputDirectory>target/reports/findbugs</xmlOutputDirectory>
<excludeFilterFile>
src/main/resources/findbugs-exclude-filters.xml
</excludeFilterFile>
</configuration>
</plugin>
</plugins>
</reporting>
My findbugs-exclude-filters.xml looks like this:
<?xml version="1.0" encoding="UTF-8"?>
<FindBugsFilter>
<Match>
<Bug category="I18N" />
</Match>
</FindBugsFilter>
QUESTIONS
Why does clean verify site report 2 warnings, but clean verify findbugs:check return 14 bugs? I don't understand what the difference is.
Why does my site report warn about I18N:DM_DEFAULT_ENCODING
The findbugs-maven-plugin plugin needs to be configured in BOTH the <reporting><plugins/></reporting> and <build><plugins/></build> section. Have experimented with this all sorts of ways and the only way I have been able to get it to work is to duplicate findbugs-maven-plugin configuration.
So try adding something like the following in your pom.xml:
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>findbugs-maven-plugin</artifactId>
<version>2.5.2</version>
<configuration>
<failOnError>false</failOnError>
<threshold>High</threshold>
<effort>Default</effort>
<xmlOutput>true</xmlOutput>
<skip>${skipFindBugs}</skip>
<xmlOutputDirectory>target/reports/findbugs</xmlOutputDirectory>
<excludeFilterFile>
src/main/resources/findbugs-exclude-filters.xml
</excludeFilterFile>
</configuration>
</plugin>
</plugins>
</build>
Note that it's a cut and paste of what you posted inside of the <reporting/> block. I have not tested the above. I'm just trying to give you a general idea here.
The Reporting section of the POM Reference states that:
And the subtler difference is that a plugin configuration under the reporting element works as build plugin configuration, although the opposite is not true (a build plugin configuration does not affect a reporting plugin).
I have been able to make this work with Maven 3.0.5. I have not tried it on 3.1.0 yet.

Resources