mvn spring-boot:build-image doesn't save image in docker - spring

I tried to create a docker image with this command
mvn spring-boot:build-image
and it shows a successful result but when I search my docker images I can't find it. Does anyone know how to fix it?
╰─⠠⠵ mvn spring-boot:build-image
...
O] [creator] Saving docker.io/library/spring-service:0.0.16-SNAPSHOT...
[INFO] [creator] *** Images (f28300653802):
[INFO] [creator] docker.io/library/spring-service:0.0.16-SNAPSHOT
[INFO] [creator] Reusing cache layer 'paketo-buildpacks/syft:syft'
[INFO] [creator] Reusing cache layer 'cache.sbom'
[INFO]
[INFO] Successfully built image 'docker.io/library/spring-service:0.0.16-SNAPSHOT'
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 28.784 s
[INFO] Finished at: 2022-09-01T18:19:01+04:30
[INFO] ------------------------------------------------------------------------
╰─⠠⠵ docker image ls
REPOSITORY TAG IMAGE ID CREATED SIZE
mariadb <none> 01d138caf7d0 8 days ago 384MB
grafana/grafana latest b6ea013786be 9 days ago 299MB
redis <none> dc7b40a0b05d 9 days ago 117MB
bitnami/zookeeper latest dd7f87e04f7b 10 days ago 521MB
bitnami/kafka latest c01437a78c04 12 days ago 664MB
prom/prometheus latest d3167094f2ef 2 weeks ago 215MB
mariadb latest 40b966d7252f 4 weeks ago 383MB
redis latest 3e42dd4e79c7 4 weeks ago 117MB
emqx/emqx latest 42418de7f6c3 4 weeks ago 148MB
portainer/portainer-ce 2.11.1 ed396c816a75 6 months ago 280MB

Nothing to worry about, the creation of your Docker images works correctly. You're just using a bit wrong command to search for newly created images.
The default «ls» command hides intermediate images. You may check the details here: https://docs.docker.com/engine/reference/commandline/image_ls/
This one should display your newly created Docker image:
docker image ls --all
Updated:
I'm using the Spring Boot Maven plugin with such configuration, which performs the build of Docker images when executing mvn install or mvn package commands:
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>${spring-boot.version}</version>
<executions>
<execution>
<goals>
<goal>build-image</goal>
</goals>
</execution>
</executions>
</plugin>
It works correctly. I'm using the 2.7.3 version of the Spring Boot and Maven plugin.

Related

Maven Install plugin: parameter file is missing or invalid

I have a local jar and I want to use it in my project. There are plenty ways to do it: just install manually into local repo, do it with script in parent pom, use system scope, use local repo declaration.
I decided to use Maven Install plugin to install jar into the repo. Here is a configuration:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-install-plugin</artifactId>
<version>2.3.1</version>
<executions>
<execution>
<phase>initialize</phase>
<goals>
<goal>install-file</goal>
</goals>
<configuration>
<groupId>jacob</groupId>
<artifactId>jacob</artifactId>
<version>1.0</version>
<packaging>jar</packaging>
<file>${basedir}\lib\jacob.jar</file>
</configuration>
</execution>
</executions>
</plugin>
I tried to run it in many ways:
mvn initialize install:install-file
mvn initialize
mvn install:install-file
But all the time I have an exception:
[ERROR] Failed to execute goal
org.apache.maven.plugins:maven-install-plugin:2.3.1:install-file
(default-cli) on project MYPROJECTNAME: The parameters 'file' for goal
org.apache.maven.plugins:maven-install-plugin:2.3.1:install-file are
missing or invalid ->
I just want to find out why it doesn't work? Looks like I am messed with phases and goals..
Finally I went another way: I placed it into my parent POM, but why it works with parent and doesn't work with child?
The best way to deal with a separated jar is to start using a repository manager and install this jar via the UI into the repository manager. From that point you can use as a usual dependency. Makes life easier.
If you like to install it as part of the build what you have tried that means you need to call maven like this:
mvn package
You should not mix up calling goals without life cylce like install:install-file with life-cycle parts as initialize.
That is the reason why you got the described error message, cause the command line part needs required parameters which you didn't gave on command line.
Combination like:
mvn install:install-file initialize
Make in Maven no sense (rarly). You have bound the maven-install-plugin to the life-clycle in your pom so you should simply call the life cylce:
mvn initalize
And you will get something like the following:
[INFO] ------------------------------------------------------------------------
[INFO] Building test 0.6-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-install-plugin:2.3.1:install-file (default) # test ---
[INFO] Installing /home/mvntest/lib/jdom-1.0.jar to /home/.m2/repository/com/soebes/test/jacob/1.1/jacob-1.1.jar
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 0.780s
[INFO] Finished at: Sat Oct 25 12:19:30 CEST 2014
[INFO] Final Memory: 6M/91M
[INFO] ------------------------------------------------------------------------
BUT: I have to say that installing an artifact like you did is bad practice. Best is to use a repository manager like Nexus, Artifactory or Archiva or if really don't like repository managers (I don't understand why, but this is a different story) you can use Stephen Connolly's non-maven-jar-maven-plugin
Apart from all the above you should use more up-to-date versions of maven-install-plugin which current version number is 2.5.2

How to force Sonatype Nexus to update?

I am trying to use onejar-maven-plugin in my pom.xml:
<plugin>
<groupId>org.dstovall</groupId>
<artifactId>onejar-maven-plugin</artifactId>
<version>1.4.4</version>
<executions>
<execution>
<configuration>
<mainClass>com.exmaple.myproj.MpPort_MpSoapPort_Client</mainClass>
<onejarVersion>0.97</onejarVersion>
<attachToBuild>true</attachToBuild>
<classifier>onejar</classifier>
</configuration>
<goals>
<goal>one-jar</goal>
</goals>
</execution>
</executions>
</plugin>
<pluginRepositories>
<pluginRepository>
<id>onejar-maven-plugin.googlecode.com</id>
<url>http://onejar-maven-plugin.googlecode.com/svn/mavenrepo</url>
</pluginRepository>
</pluginRepositories>
but for some reason, attempting to build it via the Eclipse Maven plugin (Maven install) results in BUILD ERROR:
Downloading: https://mynexus.example.com/nexus/content/repositories/central/org/dstovall/onejar-maven-plugin/1.4.4/onejar-maven-plugin-1.4.4.pom
[INFO] Unable to find resource 'org.dstovall:onejar-maven-plugin:pom:1.4.4' in repository onejar-maven-plugin.googlecode.com (http://onejar-maven-plugin.googlecode.com/svn/mavenrepo)
Downloading: https://mynexus.example.com/nexus/content/repositories/central/org/dstovall/onejar-maven-plugin/1.4.4/onejar-maven-plugin-1.4.4.pom
[INFO] Unable to find resource 'org.dstovall:onejar-maven-plugin:pom:1.4.4' in repository central (http://repo1.maven.org/maven2)
Downloading: https://mynexus.example.com/nexus/content/repositories/central/org/dstovall/onejar-maven-plugin/1.4.4/onejar-maven-plugin-1.4.4.pom
[INFO] Unable to find resource 'org.dstovall:onejar-maven-plugin:pom:1.4.4' in repository central (http://repo1.maven.org/maven2)
[INFO] ------------------------------------------------------------------------
[ERROR] BUILD ERROR
[INFO] ------------------------------------------------------------------------
[INFO] Error building POM (may not be this project's POM).
Project ID: org.dstovall:onejar-maven-plugin
Reason: POM 'org.dstovall:onejar-maven-plugin' not found in repository: Unable to download the artifact from any repository
org.dstovall:onejar-maven-plugin:pom:1.4.4
from the specified remote repositories:
Nexus (https://mynexus.example.com/nexus/content/repositories/central)
for project org.dstovall:onejar-maven-plugin
So I manually downloaded onejar-maven-plugin.jar and install it through the command line and I seem to be getting a similar error:
C:\Users\daniel\myproj>mvn install:install-file -Dfile=onejar-maven-plugin-1.4.4.jar -DgroupId=com.jolira -DartifactId=onejar-maven-plugin -Dversion=1.4.4 -Dpackaging=jar
[INFO] Scanning for projects...
Downloading: https://mynexus.example.com/nexus/content/repositories/central/org/dstovall/onejar-maven-plugin/1.4.4/onejar-maven-plugin-1.4.4.pom
[INFO] Unable to find resource 'org.dstovall:onejar-maven-plugin:pom:1.4.4' in repository onejar-maven-plugin.googlecode.com (http://onejar-maven-plugin.googlecode.com/svn/mavenrepo)
Downloading: https://mynexus.example.com/nexus/content/repositories/central/org/dstovall/onejar-maven-plugin/1.4.4/onejar-maven-plugin-1.4.4.pom
[INFO] Unable to find resource 'org.dstovall:onejar-maven-plugin:pom:1.4.4' in repository central (http://repo1.maven.org/maven2)
Downloading: https://mynexus.example.com/nexus/content/repositories/central/org/dstovall/onejar-maven-plugin/1.4.4/onejar-maven-plugin-1.4.4.pom
[INFO] Unable to find resource 'org.dstovall:onejar-maven-plugin:pom:1.4.4' in repository central (http://repo1.maven.org/maven2)
[INFO] ------------------------------------------------------------------------
[ERROR] BUILD ERROR
[INFO] ------------------------------------------------------------------------
[INFO] Error building POM (may not be this project's POM).
Project ID: org.dstovall:onejar-maven-plugin
Reason: POM 'org.dstovall:onejar-maven-plugin' not found in repository: Unable to download the artifact from any repository
org.dstovall:onejar-maven-plugin:pom:1.4.4
from the specified remote repositories:
Nexus (https://mynexus.example.com/nexus/content/repositories/central)
for project org.dstovall:onejar-maven-plugin
My understanding is that because we have a Nexus mirror which doesn't contain that particular artifact, things get confused.
So I tried following the instructions on How to force Sonatype Nexus Regenerate / Reindex its Metadata but the “Browse Index” tab has no such context menu! on our Sonatype Nexus.
I read here that "Nexus only caches artifacts that clients have requested. So you need to set up your project poms to request the proper versions". But that's exactly what I have been doing -- without any change in the outcome.
How do I get out of this "chicken & egg" situation and get this onejar-maven-plugin ver. 1.4.4 into my Nexus mirror?
(Alternatively, how do I get it into my local .m2 cache?)
You can force Maven to update and request dependencies again even if the local repo contains metadata about artifacts not be available with -U
mvn clean install -U
should work.
Also you should change your settings.xml to point to the public group instead of just the central repo directly. More can be found in the Nexus book.
And you should note that the Central Repository does not have the onejar plugin you are trying to use. Check out the search results and see how the groupId is com.joilira and not org.dstovall
Further more if you really want to use the onejar plugin from org.dstovall you should add the url http://onejar-maven-plugin.googlecode.com/svn/mavenrepo/ as a proxy repository to Nexus, add it to the public group and then use the public group in your settings.xml

Displaying custom test results in Jenkins Maven job

I just added some Python unit tests to an existing Maven POM but I can't seem to get Jenkins to report the results of the tests when it runs the build.
I'm running nose tests from Maven with the exec-maven-plugin during the "test" phase. The tests run successfully from the Jenkins job and generate an xUnit compatible test report to target/surefire-reports/TEST-nosetests.xml, but Jenkins doesn't pick up on the results.
Interestingly, Maven also reports no tests run before executing the test suite:
-------------------------------------------------------
T E S T S
-------------------------------------------------------
There are no tests to run.
Results :
Tests run: 0, Failures: 0, Errors: 0, Skipped: 0
[INFO]
[INFO] --- exec-maven-plugin:1.1.1:exec (nosetests) # server ---
[INFO] ................
[INFO] ----------------------------------------------------------------------
[INFO] Ran 16 tests in 194.799s
[INFO]
[INFO] OK
[INFO] Registering compile source root /Volumes/Data/workspace/myProject/target
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
So is this a problem with Jenkins not seeing the results, or with Maven not treating my test suite as actual tests?
I worked through this problem by using a "free-style software project" in Jenkins rather than the "maven2/3" project.
Under Build, choose Add build step and configure the project to Invoke top-level Maven targets. I'm using the test target.
Finally, under Post-build Actions choose Add post-build action of Publish JUnit test result report and point it at the xUnit output from your tests. This option is not available for Maven 2/3 jobs for some reason.
To build upon the answer by bpanulla, if you have tests in more than one sub-directory of your project, you can use a wildcard in the "Test report XMLs" field, such as: **/target/surefire-reports/*.xml
If you have a more modular Jenkins setup using a free project will not correctly build submodules. If the maven-plugin that generates the reports execution id is e2eTests, then add the following snippet to your pom.xml and the jenkins maven plugin will take care of the rest!
<properties>
    <jenkins.e2eTests.reportsDirectory>target/protractor-reports</jenkins.e2eTests.reportsDirectory>
</properties>
See https://wiki.jenkins-ci.org/display/JENKINS/Building+a+maven2+project
Try after adding the maven compiler plugin
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.0</version>
<executions>
<execution>
<id>default-testCompile</id>
<phase>compile</phase>
<goals>
<goal>testCompile</goal>
</goals>
</execution>
</executions>
<configuration>
<encoding>ISO-8859-1</encoding>
<source>1.8</source>
<target>1.8</target>
<useIncrementalCompilation>false</useIncrementalCompilation>
<testSource>1.8</testSource>
<testTarget>1.8</testTarget>
</configuration>
</plugin>
As you can see in the Tests run output that Maven didn't recognized the tests as tests. Furthermore to see the results in Jenkins you need to check if nope can create junit compatible output result files (which i assume) which can be read by jenkins and of course displayed.

Process forked out of Maven release:perform plugin ignores user's settings.xml?

As per the documentation, the Maven release:perform goal checks out the project and then forks a new Maven instance to build it. For some reason the forked instance appears to ignore the user's settings.xml, which causes an error in my case because that file has the definition of a property that is used to compose the repository's URL in the parent pom.
User's settings.xml
Definition of a property in a "nexus" profile which is always active.
<profiles>
<profile>
<id>nexus</id>
<properties>
<dist.url>http://host.com/nexus/content/repositories</dist.url>
</properties>
</profile>
</profiles>
<activeProfiles>
<activeProfile>nexus</activeProfile>
</activeProfiles>
Parent's pom.xml
Usage of the defined property to compose the repository's URL.
<distributionManagement>
<repository>
<id>nexus</id>
<url>${dist.url}/releases</url>
</repository>
</distributionManagement>
Command executed:
mvn release:perform
Output (after it indicates having successfully checked out, built, tested and packaged the project):
[INFO] Uploading: ${dist.url}/releases/com/acme/access/my-project/1.0/my-project-1.0.jar
[INFO] [INFO] ------------------------------------------------------------------------
[INFO] [INFO] BUILD FAILURE
[INFO] [INFO] ------------------------------------------------------------------------
[INFO] [INFO] Total time: 3.659s
[INFO] [INFO] Finished at: Wed Aug 01 14:40:23 EDT 2012
[INFO] [INFO] Final Memory: 21M/307M
[INFO] [INFO] ------------------------------------------------------------------------
[INFO] [WARNING] The requested profile "nexus" could not be activated because it does not exist.
[INFO] [ERROR] Failed to execute goal org.apache.maven.plugins:maven-deploy-plugin:2.7:deploy (default-deploy) on project my-project: Failed to deploy artifacts: Could not transfer artifact com.acme.access:my-project:jar:1.0 from/to nexus (${dist.url}/releases): Error transferring file: no protocol: ${dist.url}/releases/com/acme/access/my-project/1.0/my-project-1.0.jar -> [Help 1]
Notice how the forked Maven instance is trying to upload to ${dist.url}, which indicates that the property defined in settings.xml was not read. Also, the warning message informs that profile "nexus" was not found. I'm assuming that the main Maven instance passed the profile information down to the forked instance so it knew to look for it, but since it ignored (or did not find) the user's settings.xml, it could not find that profile.
The only way I have found to circumvent this is to manually specify the location of the settings.xml file through the use of Maven's command line -s argument "wrapped" by the plugin's arguments argument, as in
mvn release:perform -Darguments="-s C:\Users\theuser\.m2\settings.xml"
Is the plugin behaving in an expected/correct way? Is there a way to keep the property definition inside the user's settings.xml without having to specify the location of the file as I have done above?
More information:
The problem seems to be specifically with the plugin not finding the user's settings.xml, as copying the profile information into the global settings.xml does cause it to work.
The user's settings.xml is properly named/created because running help:active-profiles indicates that the profile is active. Manually building and deploying with mvn clean deploy also works correctly (ie, the repository URL is correctly calculated and the artifact is uploaded).
It's not necessarily a bug in the maven-release-plugin. It seems that you ran into this Maven bug: MNG-5224
The bug should be fixed in Maven 3.0.4.

maven site unpack error

I have a multi module maven project. If I run
mvn clean install
everything works fine. But if I run:
mvn site
I get the following error:
[INFO] --- maven-dependency-plugin:2.4:unpack (copy-war) # module2 ---
[INFO] Configured Artifact: com.example:module1:1.0-SNAPSHOT:war
Unpacking path\2\module1\target\classes to path\2\module2\target\module1 with includes "" and excludes ""
org.codehaus.plexus.archiver.ArchiverException: The source must not be a directory.
With mvn clean install at the same point I get:
[INFO] --- maven-dependency-plugin:2.4:unpack (copy-war) # module2 ---
[INFO] Configured Artifact: com.example:module1:1.0-SNAPSHOT:war
[INFO] Unpacking path\2\module1\target\module1-1.0-SNAPSHOT.war to path\2\module2\target\module1 with includes "" and excludes ""
and everything works fine.
Any idea why the dependency plugin wants to unpack a directory instead of a war?
I found a workaround. I disabled the site plugin for that module:
<plugin>
<artifactId>maven-site-plugin</artifactId>
<configuration>
<generateReports>false</generateReports>
</configuration>
</plugin>
I think the comand fails due to a bug in the site plugin.
This is indeed a long standing (since 2007!) bug in maven-dependency-plugin. Have a look at the MDEP-98 JIRA issue for a discussion and possible workarounds.

Resources