I would like to be able to run spring-boot:build-image and have it pull the paketobuildpack from our local Artifactory server instead of docker.io. I want the plugin to use the docker config file for my credentials and not hard code them in the pom file.
This works:
<docker>
<builderRegistry>
<username>username</username>
<password>password</password>
<url>https://artifactory.mycompany.com/v2/</url>
</builderRegistry>
</docker>
When I run mvn spring-boot:build-image, without the docker block above, I get the following error:
[ERROR] Failed to execute goal org.springframework.boot:spring-boot-maven-plugin:2.4.2:build-image (default-cli) on project demo: Execution default-cli of goal org.springframework.boot:spring-boot-maven-plugin:2.4.2:build-image failed: Docker API call to 'localhost/v1.24/images/create?fromImage=artifactory.mycompany.com%2Fcommon-docker-virtual%2Fpaketobuildpacks%2Fbuilder%3Abase'
failed with status code 500 "Internal Server Error" and message "Head https://artifactory.mycompany.com/v2/common-docker-virtual/paketobuildpacks/builder/manifests/base:
unknown: Authentication is required" -> [Help 1]
My .docker/config.json has the following configuration:
{
"auths": {
"artifactory.mycompany.com": {
"auth": "**token**",
"email": "myemail#mycompany.com"
}
},
"credStore": "desktop",
"credsStore": "desktop"
}
I can successfully run docker build that uses our Artifactory successfully for other unrelated images.
My pom.xml
<?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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.4.2</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.penske.architecture</groupId>
<artifactId>myapp</artifactId>
<version>1.0.0.RELEASE</version>
<name>myapp</name>
<properties>
<maven.compiler.target>14</maven.compiler.target>
<maven.compiler.source>14</maven.compiler.source>
<java.version>14</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-ldap</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-mongodb</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<scope>runtime</scope>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-configuration-processor</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.11</version>
</dependency>
</dependencies>
<build>
<finalName>${project.artifactId}</finalName>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<layers>
<enabled>true</enabled>
</layers>
<image>
<name>artifactory.mycompany.com/common-docker-virtual/library/${project.artifactId}</name>
<builder>artifactory.mycompany.com/common-docker-virtual/paketobuildpacks/builder:base</builder>
<env>
<BP_JVM_VERSION>14</BP_JVM_VERSION>
</env>
</image>
</configuration>
<executions>
<execution>
<goals>
<goal>build-image</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
The full maven output
[INFO] Scanning for projects...
[INFO]
[INFO] ----------< my.group:myapp >-----------
[INFO] Building myapp 1.0.0.RELEASE
[INFO] --------------------------------[ jar ]---------------------------------
[INFO]
[INFO] >>> spring-boot-maven-plugin:2.4.2:build-image (default-cli) > package # myapp >>>
[INFO]
[INFO] --- maven-resources-plugin:3.2.0:resources (default-resources) # myapp ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Using 'UTF-8' encoding to copy filtered properties files.
[INFO] Copying 3 resources
[INFO] Copying 1 resource
[INFO]
[INFO] --- maven-compiler-plugin:3.8.1:compile (default-compile) # myapp ---
[INFO] Nothing to compile - all classes are up to date
[INFO]
[INFO] --- maven-resources-plugin:3.2.0:testResources (default-testResources) # myapp ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Using 'UTF-8' encoding to copy filtered properties files.
[INFO] skip non existing resourceDirectory C:\myapp\src\test\resources
[INFO]
[INFO] --- maven-compiler-plugin:3.8.1:testCompile (default-testCompile) # myapp ---
[INFO] No sources to compile
[INFO]
[INFO] --- maven-surefire-plugin:2.22.2:test (default-test) # myapp ---
[INFO] No tests to run.
[INFO]
[INFO] --- maven-jar-plugin:3.2.0:jar (default-jar) # myapp ---
[INFO] Building jar: C:\myapp\target\ldap-changelog-exporter.jar
[INFO]
[INFO] --- spring-boot-maven-plugin:2.4.2:repackage (repackage) # myapp ---
[INFO] Replacing main artifact with repackaged archive
[INFO]
[INFO] <<< spring-boot-maven-plugin:2.4.2:build-image (default-cli) < package # myapp <<<
[INFO]
[INFO]
[INFO] --- spring-boot-maven-plugin:2.4.2:build-image (default-cli) # myapp ---
[INFO] Building image 'artifactory.mycompany.com/common-docker-virtual/library/myapp:latest'
[INFO]
[INFO] > Pulling builder image 'artifactory.mycompany.com/common-docker-virtual/paketobuildpacks/builder:base' 100%
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 9.024 s
[INFO] Finished at: 2021-02-11T16:48:27-05:00
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.springframework.boot:spring-boot-maven-plugin:2.4.2:build-image (default-cli) on project myapp: Execution default-cli of goal org.springframework.boot:spring-boot-maven-plugin:2.4.2:build-image failed: Docker API call to 'localhost/v1.24/images/create?fromImage=artifactory.mycompany.com%2Fcommon-docker-virtual%2Fpaketobuildpacks%2Fbuilder%3Abase' failed with status code 500 "Internal Server Error" and message "Head https://artifactory.mycompany.com/v2/common-docker-virtual/paketobuildpacks/builder/manifests/base: unknown: Authentication is required" -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/PluginExecutionException
Process finished with exit code 1
Put credentials into settings.xml (~/.m2/settings.xml or whatever you specify by -s in mvn command) inside properties section (https://maven.apache.org/settings.html#Profiles)
and then in your pom.xml replace hardcoded values with defined variable names.
If you use environment variables (${env.something}), you can even skip settings.xml and define them from cli.
Related
I'm using Spring declaring it at dependencyManagement:
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-dependencies</artifactId>
<version>2.7.0</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
Inside org.springframework.boot:spring-boot-dependencies:2.7.0 is defined a property:
<properties>
...
<lombok.version>1.18.24</lombok.version>
...
</properties>
Problem is I need to make use of it from my pom:
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.10.1</version>
<configuration>
<release>${java.version}</release>
<annotationProcessorPaths>
<annotationProcessorPath>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>${lombok.version}</version>
</annotationProcessorPath>
<annotationProcessorPath>
<groupId>org.mapstruct</groupId>
<artifactId>mapstruct-processor</artifactId>
<version>${org.mapstruct.version}</version>
</annotationProcessorPath>
</annotationProcessorPaths>
</configuration>
</plugin>
</plugins>
</build>
This property is not found:
~/projects/cultura/git/repositories/backend develop* ❯ mvn compile 14:56:41
[INFO] Scanning for projects...
[INFO]
[INFO] ---------------------< cat.gencat.clt.git:backend >---------------------
[INFO] Building backend 0.0.1-SNAPSHOT
[INFO] --------------------------------[ jar ]---------------------------------
[INFO]
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) # backend ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 3 resources
[INFO]
[INFO] --- maven-compiler-plugin:3.10.1:compile (default-compile) # backend ---
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 5.092 s
[INFO] Finished at: 2022-08-23T14:56:52+02:00
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.10.1:compile (default-compile) on project backend: Resolution of annotationProcessorPath dependencies failed: For artifact {org.projectlombok:lombok:null:jar}: The version cannot be empty. -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
Is there any way to make a reference to lombok property defined into spring bom properties?
I have just downloaded from spring.io a project with the only "web" dependency. Here's the pom.xml:
<?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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.7.3</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>microservices.book</groupId>
<artifactId>social-multiplication</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>social-multiplication</name>
<description>Social Multiplication App</description>
<properties>
<java.version>18</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
When from the terminal I give:
mvn spring-boot:run
I get:
[INFO] Scanning for projects...
[INFO]
[INFO] --------------< microservices.book:social-multiplication >--------------
[INFO] Building social-multiplication 0.0.1-SNAPSHOT
[INFO] --------------------------------[ jar ]---------------------------------
[INFO]
[INFO] >>> spring-boot-maven-plugin:2.7.3:run (default-cli) > test-compile # social-multiplication >>>
[INFO]
[INFO] --- maven-resources-plugin:3.2.0:resources (default-resources) # social-multiplication ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Using 'UTF-8' encoding to copy filtered properties files.
[INFO] Copying 1 resource
[INFO] Copying 0 resource
[INFO]
[INFO] --- maven-compiler-plugin:3.10.1:compile (default-compile) # social-multiplication ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 1 source file to C:\Users\Massimo\Desktop\Programming\social-multiplication\social-multiplication\target\classes
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1.084 s
[INFO] Finished at: 2022-09-11T23:25:39+02:00
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.10.1:compile (default-compile) on project social-multip
lication: Fatal error compiling: invalid target release: 18 -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException
I've looked both at this and this SO question but that's not my case.
> echo %JAVA_HOME%
C:\Program Files\Java\jdk1.8.0_161
> echo %JAVA_jdk%
C:\Program Files\Java\jdk1.8.0_161
and I'm trying to build a java 18 application.
So what's the problem? Also I would like to know something about the maven specified in the pom. It's not the "standard" maven that I call from the terminal right?
What artifat is it downloading?
I'm on windows 10, Intellij Idea 2020.2, and my maven version is:
> mvn --version
Maven home: C:\Program Files\apache-maven-3.8.6-bin\apache-maven-3.8.6
Java version: 1.8.0_161, vendor: Oracle Corporation, runtime: C:\Program Files\Java\jdk1.8.0_161\jre
Default locale: it_IT, platform encoding: Cp1252
OS name: "windows 10", version: "10.0", arch: "amd64", family: "windws"
I created simple telegram bot on Spring Boot and I am trying to deploy it to the server. So, to do this I need to create executable jar file. I built jar using mvn clean package, but it does not work. I can't run this jar from anywhere, except project root folder. When I run it from root folder everything works fine, otherwise I get an exception. I suspect that this strange behaviour is due to errors in dependencies. I've tried a lot of things, like change spring boot maven plugin's target, change jar to war, but nothing works. Is there any ideas how I can fix it and build jar correctly? Thanks for any help.
Project pom file:
<?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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.6.4</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<packaging>jar</packaging>
<groupId>com.example</groupId>
<artifactId>rf3dBot</artifactId>
<version>1.0</version>
<name>rf3dBot</name>
<description>rf3dBot</description>
<properties>
<java.version>17</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.telegram</groupId>
<artifactId>telegrambots-spring-boot-starter</artifactId>
<version>5.7.1</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-log4j</artifactId>
<version>1.3.8.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-configuration-processor</artifactId>
<version>2.6.4</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
build logs:
$ mvn clean package
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------< com.example:rf3dBot >-------------------------
[INFO] Building rf3dBot 1.0
[INFO] --------------------------------[ jar ]---------------------------------
[WARNING] The artifact org.slf4j:slf4j-log4j12:jar:1.7.36 has been relocated to org.slf4j:slf4j-reload4j:jar:1.7.36
[INFO]
[INFO] --- maven-clean-plugin:3.1.0:clean (default-clean) # rf3dBot ---
[INFO] Deleting C:\Users\Sergey\Desktop\rf3dBot\target
[INFO]
[INFO] --- maven-resources-plugin:3.2.0:resources (default-resources) # rf3dBot ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Using 'UTF-8' encoding to copy filtered properties files.
[INFO] Copying 1 resource
[INFO] Copying 755 resources
[INFO]
[INFO] --- maven-compiler-plugin:3.8.1:compile (default-compile) # rf3dBot ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 10 source files to C:\Users\Sergey\Desktop\rf3dBot\target\classes
[INFO]
[INFO] --- maven-resources-plugin:3.2.0:testResources (default-testResources) # rf3dBot ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Using 'UTF-8' encoding to copy filtered properties files.
[INFO] skip non existing resourceDirectory C:\Users\Sergey\Desktop\rf3dBot\src\test\resources
[INFO]
[INFO] --- maven-compiler-plugin:3.8.1:testCompile (default-testCompile) # rf3dBot ---
[INFO] No sources to compile
[INFO]
[INFO] --- maven-surefire-plugin:2.22.2:test (default-test) # rf3dBot ---
[INFO] No tests to run.
[INFO]
[INFO] --- maven-jar-plugin:3.2.2:jar (default-jar) # rf3dBot ---
[INFO] Building jar: C:\Users\Sergey\Desktop\rf3dBot\target\rf3dBot-1.0.jar
[INFO]
[INFO] --- spring-boot-maven-plugin:2.6.4:repackage (repackage) # rf3dBot ---
[INFO] Replacing main artifact with repackaged archive
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 28.204 s
[INFO] Finished at: 2022-03-26T00:22:44+03:00
[INFO] ------------------------------------------------------------------------
exception (it's not so important, because in the intellij idea application works completely fine)
try
starting your app with a specified profile.
error in image shows it gives null pointer exception in RandomMemeBuilder.
U should look this class and check what is causing null pointer execption. or post more code for this class.
I have a non-modular javafx project and want to run it with maven but i have no experience in it.
I'm using IntelliJ IDEA so I went to root directory, right click -> Add Framework Support, and choose maven. a pom.xml file was added.
After referring https://openjfx.io/openjfx-docs/#maven I modified The pom.xml file to look like this:
<?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>org.openjfx</groupId>
<artifactId>AccountZeyny</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
<name>AccountZeyny</name>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.release>11</maven.compiler.release>
<javafx.version>15</javafx.version>
<javafx.maven.plugin.version>0.0.6</javafx.maven.plugin.version>
</properties>
<organization>
<!-- Used as the 'Vendor' for JNLP generation -->
<name>ORGZ</name>
</organization>
<dependencies>
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-controls</artifactId>
<version>15</version>
</dependency>
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-fxml</artifactId>
<version>15</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<release>${maven.compiler.release}</release>
</configuration>
</plugin>
<plugin>
<groupId>org.openjfx</groupId>
<artifactId>javafx-maven-plugin</artifactId>
<version>0.0.6</version>
<configuration>
<release>${maven.compiler.release}</release>
<mainClass>org.openjfx.Main</mainClass>
</configuration>
</plugin>
</plugins>
</build>
</project>
I went to Maven tab -> Plugins -> compiler -> compiler:compile. and then Plugins -> javafx -> javafx:run. and I got this in the run tab down below:
D:\openjdk-15.0.1_windows-x64_bin\jdk-15.0.1\bin\java.exe -Dmaven.multiModuleProjectDirectory=D:\Account-Zeyny "-Dmaven.home=D:\IntelliJ IDEA Community Edition 2021.1.3\plugins\maven\lib\maven3" "-Dclassworlds.conf=D:\IntelliJ IDEA Community Edition 2021.1.3\plugins\maven\lib\maven3\bin\m2.conf" "-Dmaven.ext.class.path=D:\IntelliJ IDEA Community Edition 2021.1.3\plugins\maven\lib\maven-event-listener.jar" "-javaagent:D:\IntelliJ IDEA Community Edition 2021.1.3\lib\idea_rt.jar=64148:D:\IntelliJ IDEA Community Edition 2021.1.3\bin" -Dfile.encoding=UTF-8 -classpath "D:\IntelliJ IDEA Community Edition 2021.1.3\plugins\maven\lib\maven3\boot\plexus-classworlds-2.6.0.jar;D:\IntelliJ IDEA Community Edition 2021.1.3\plugins\maven\lib\maven3\boot\plexus-classworlds.license" org.codehaus.classworlds.Launcher -Didea.version=2021.1.3 org.openjfx:javafx-maven-plugin:0.0.6:run
[INFO] Scanning for projects...
[INFO]
[INFO] ----------------------< org.openjfx:AccountZeyny >----------------------
[INFO] Building AccountZeyny 1.0-SNAPSHOT
[INFO] --------------------------------[ jar ]---------------------------------
[INFO]
[INFO] >>> javafx-maven-plugin:0.0.6:run (default-cli) > process-classes # AccountZeyny >>>
[INFO]
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) # AccountZeyny ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory D:\Account-Zeyny\src\main\resources
[INFO]
[INFO] --- maven-compiler-plugin:3.8.1:compile (default-compile) # AccountZeyny ---
[INFO] No sources to compile
[INFO]
[INFO] <<< javafx-maven-plugin:0.0.6:run (default-cli) < process-classes # AccountZeyny <<<
[INFO]
[INFO]
[INFO] --- javafx-maven-plugin:0.0.6:run (default-cli) # AccountZeyny ---
[INFO] Toolchain in javafx-maven-plugin null
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 25.189 s
[INFO] Finished at: 2021-07-15T18:02:32+03:00
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.openjfx:javafx-maven-plugin:0.0.6:run (default-cli) on project AccountZeyny: Error: Error: Output directory is empty -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException
Process finished with exit code 1
Did I make mistake in these steps?
EDIT: I'm using IntelliJ IDEA 2021.1.3 x64.
I created a new maven junit5 framework project to test existing java projects. I added the java project in build path of the newly created maven junit5 framework project. I right clicked the method I wanted to add junit test case for and selected new junit test case and changed the source folder to the new maven junit5 framework project src directory and left the rest of the options as default. Created the junit test and ran the test as a unit test without any issues(screenshot below). Running the same test using maven getting the error below. I added the surefire plugin in pom(below) but still getting the error below. Using eclipse.
-------------------------------------------------------------------------------
Test set: com.build.VersionInfoTest
-------------------------------------------------------------------------------
Tests run: 1, Failures: 0, Errors: 1, Skipped: 0, Time elapsed: 0.003 s <<< FAILURE! - in com.build.VersionInfoTest
com.build.VersionInfoTest Time elapsed: 0.002 s <<< ERROR!
java.lang.NoClassDefFoundError: Lcom/build/VersionInfo;
Caused by: java.lang.ClassNotFoundException: com.build.VersionInfo
<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>UnitTesting</groupId>
<artifactId>com.unit.testing</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>com.unit.testing</name>
<description>Junit Tests</description>
<packaging>jar</packaging>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<junit.jupiter.version>5.5.2</junit.jupiter.version>
<junit.platform.version>1.5.2</junit.platform.version>
</properties>
<dependencies>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>${junit.jupiter.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.platform</groupId>
<artifactId>junit-platform-runner</artifactId>
<version>${junit.platform.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>${junit.jupiter.version}</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
</plugin>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.2</version>
</plugin>
</plugins>
</build>
</project>
Update : I cleaned up the pom(below) but now no tests discovered? when I run the project with junit the test is discovered?
[INFO] Scanning for projects...
[INFO]
[INFO] --------------< UnitTesting:com.unit.testing >---------------
[INFO] Building com.unit.testing 1.0-SNAPSHOT
[INFO] --------------------------------[ jar ]---------------------- -----------
[INFO]
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) # com.unit.testing ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 0 resource
[INFO]
[INFO] --- maven-compiler-plugin:3.1:compile (default-compile) # com.unit.testing ---
[INFO] Nothing to compile - all classes are up to date
[INFO]
[INFO] --- maven-resources-plugin:2.6:testResources (default- testResources) # com.unit.testing ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 0 resource
[INFO]
[INFO] --- maven-compiler-plugin:3.1:testCompile (default-testCompile) # com.unit.testing ---
[INFO] Nothing to compile - all classes are up to date
[INFO]
[INFO] --- maven-surefire-plugin:3.0.0-M4:test (default-test) # com.unit.testing ---
[INFO]
[INFO] -------------------------------------------------------
[INFO] T E S T S
[INFO] -------------------------------------------------------
[INFO] Running com.build.VersionInfoTest
[INFO] Tests run: 0, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.002 s - in com.build.VersionInfoTest
[INFO]
[INFO] Results:
[INFO]
[INFO] Tests run: 0, Failures: 0, Errors: 0, Skipped: 0
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1.955 s
[INFO] Finished at: 2020-03-09T10:00:22-04:00
[INFO] ------------------------------------------------------------------------
<packaging>jar</packaging>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>${maven.compiler.source}</maven.compiler.target>
<junit.jupiter.version>5.6.0</junit.jupiter.version>
</properties>
<dependencies>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
<version>${junit.jupiter.version}</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0-M4</version>
</plugin>
</plugins>
</build>
package com.dbb.build
import static org.junit.jupiter.api.Assertions.*;
import org.junit.jupiter.api.Test;
import com.dbb.build.VersionInfo;
class VersionInfoTest {
VersionInfo versionInfo = VersionInfo.getInstance();
#Test
void getVersion() {
String version = versionInfo.getVersion();
System.out.println(version);
assertNotNull(versionInfo.getVersion(), "expected a return value of"+version+"but was null");
}
}
UPDATE:
[INFO] --- maven-resources-plugin:2.6:testResources (default- testResources) # DBB-Unit-Testing ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 0 resource
[INFO]
[INFO] --- maven-compiler-plugin:3.8.1:testCompile (default-testCompile) # DBB-Unit-Testing ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 1 source file to /Unit-Testing/target/test-classes
[INFO] -------------------------------------------------------------
[ERROR] COMPILATION ERROR :
[INFO] -------------------------------------------------------------
[ERROR] /Unit-Testing/src/test/java/com/VersionInfoTest.java:[7,25] cannot find symbol
symbol: class VersionInfo
location: package com.build
[ERROR] /Unit-Testing/src/test/java/com/build/VersionInfoTest.java: [11,9] cannot find symbol
symbol: class VersionInfo
location: class com.build.TestVersionInfo
[ERROR] /Unit-Testing/src/test/java/com/ /build/VersionInfoTest.java: [11,35] cannot find symbol
symbol: variable VersionInfo
location: class com.build.TestVersionInfo
[INFO] 3 errors
Solution: Using junit-platform-console-standalone-1.5.2.jar and run units via command line. Looks like if we have a non maven project junit-platform-console-standalone seems to be a better option.
Here is a sample of some of my pom I use with Maven 3.x and tests executed as expected with JUnit 5 in Eclipse but also from command line:
Don't add too many Juniper artifacts, some will create some side effect if present.
Note also the updated version of the surefire plugin with had some issue in the past with JUnit5
<properties>
<!-- ensure proper encoding of source and resource files in the project -->
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<junit-5.version>5.6.0</junit-5.version>
</properties>
<dependencies>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
<version>${junit-5.version}</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0-M4</version>
</plugin>
</plugins>
</build>
UPDATE:
You can find a small example here: https://gist.github.com/asa-git/8e34bbc51b5fcb09b7fab3efdaaa73c9
Note that I am using maven version 3.6.3 and a JDK 8.
Furthermore, when running from the command line on windows (but likewise on other systems), you need to make sure your JDK is on your path before any other JSE installed on your system.