I have a question regarding the execution order of maven-assembly-plugin and maven-jar-plugin. What I am trying to do is to put together an uberjar file for the pf4j framework (plugin framework for java). For this to be able to do I need to first assemble all the code with dependencies and then package the jar with the manifest file which has some specific entries needed by the pf4j framework.
In the issue "Changing the order of maven plugin execution"
I read in the answer that order of plugins which are bound to the same phase is defined by the order declared in the pom.xml file. Now I have the following pom.xml 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 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.assembly.test</groupId>
<artifactId>assembly-test</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<java.version>1.8</java.version>
<plugin.id>some-plugin</plugin.id>
<plugin.class>org.assembly.test.Main</plugin.class>
<plugin.version>0.0.1</plugin.version>
<plugin.provider>Developers</plugin.provider>
<plugin.dependencies />
</properties>
<build>
<plugins>
<!-- Compiler Plugin -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>${java.version}</source>
<target>${java.version}</target>
</configuration>
</plugin>
<!-- Assembly Plugin -->
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<version>3.0.0</version>
<configuration>
<filters>
<filter>src/main/assembly/filter.properties</filter>
</filters>
<descriptors>
<descriptor>src/main/assembly/assembly.xml</descriptor>
</descriptors>
</configuration>
<executions>
<execution>
<id>make-assembly</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
<!-- Jar Plugin -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<configuration>
<classesDirectory>${project.build.directory}/${project.artifactId}-${project.version}-distro</classesDirectory>
<archive>
<manifestEntries>
<Plugin-Id>${plugin.id}</Plugin-Id>
<Plugin-Class>${plugin.class}</Plugin-Class>
<Plugin-Version>${plugin.version}</Plugin-Version>
<Plugin-Provider>${plugin.provider}</Plugin-Provider>
<Plugin-Dependencies>${plugin.dependencies}</Plugin-Dependencies>
</manifestEntries>
</archive>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<!-- https://mvnrepository.com/artifact/org.apache.commons/commons-lang3 -->
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.5</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>
From the pom.xml file it should be clear that I want to run the maven-jar-plugin after maven-assembly-plugin. But instead I get the following maven output:
[INFO] Scanning for projects...
[WARNING]
[WARNING] Some problems were encountered while building the effective model for org.assembly.test:assembly-test:jar:1.0-SNAPSHOT
[WARNING] 'build.plugins.plugin.version' for org.apache.maven.plugins:maven-jar-plugin is missing. # line 82, column 12
[WARNING]
[WARNING] It is highly recommended to fix these problems because they threaten the stability of your build.
[WARNING]
[WARNING] For this reason, future Maven versions might no longer support building such malformed projects.
[WARNING]
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building assembly-test 1.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-clean-plugin:2.5:clean (default-clean) # assembly-test ---
[INFO] Deleting D:\JavaTools\project_btc\projects\assembly-test\target
[INFO]
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) # assembly-test ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 3 resources
[INFO]
[INFO] --- maven-compiler-plugin:3.1:compile (default-compile) # assembly-test ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 5 source files to D:\JavaTools\project_btc\projects\assembly-test\target\classes
[INFO]
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) # assembly-test ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 0 resource
[INFO]
[INFO] --- maven-compiler-plugin:3.1:testCompile (default-testCompile) # assembly-test ---
[INFO] Nothing to compile - all classes are up to date
[INFO]
[INFO] --- maven-surefire-plugin:2.12.4:test (default-test) # assembly-test ---
[INFO]
[INFO] --- maven-jar-plugin:2.4:jar (default-jar) # assembly-test ---
[WARNING] JAR will be empty - no content was marked for inclusion!
[INFO] Building jar: D:\JavaTools\project_btc\projects\assembly-test\target\assembly-test-1.0-SNAPSHOT.jar
[INFO]
[INFO] --- maven-assembly-plugin:3.0.0:single (make-assembly) # assembly-test ---
[INFO] Reading assembly descriptor: src/main/assembly/assembly.xml
[ERROR] OS=Windows and the assembly descriptor contains a *nix-specific root-relative-reference (starting with slash) /
[INFO] Copying files to D:\JavaTools\project_btc\projects\assembly-test\target\assembly-test-1.0-SNAPSHOT-distro
[WARNING] Assembly file: D:\JavaTools\project_btc\projects\assembly-test\target\assembly-test-1.0-SNAPSHOT-distro is not a regular file (it may be a directory). It cannot be attached to the project build for installation or deployment.
[INFO]
[INFO] --- maven-install-plugin:2.4:install (default-install) # assembly-test ---
[INFO] Installing D:\JavaTools\project_btc\projects\assembly-test\target\assembly-test-1.0-SNAPSHOT.jar to D:\JavaTools\maven_repository\org\assembly\test\assembly-test\1.0-SNAPSHOT\assembly-test-1.0-SNAPSHOT.jar
[INFO] Installing D:\JavaTools\project_btc\projects\assembly-test\pom.xml to D:\JavaTools\maven_repository\org\assembly\test\assembly-test\1.0-SNAPSHOT\assembly-test-1.0-SNAPSHOT.pom
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 4.376 s
[INFO] Finished at: 2017-04-04T06:04:11+02:00
[INFO] Final Memory: 21M/168M
[INFO] ------------------------------------------------------------------------
Now from the output it can be seen that maven-jar-plugin is executed before the maven-assembly-plugin, which is not what I wanted. The effect of such an order is a jar file with only MANIFEST_INF content.
Can somebody explain me what am I doing wrong here?
One possible solution is to make pom file in such a way:
<?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.assembly.test</groupId>
<artifactId>assembly-test</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<java.version>1.8</java.version>
<plugin.id>some-plugin</plugin.id>
<plugin.class>org.assembly.test.Main</plugin.class>
<plugin.version>0.0.1</plugin.version>
<plugin.provider>Developers</plugin.provider>
<plugin.dependencies />
</properties>
<build>
<plugins>
<!-- Compiler Plugin -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>${java.version}</source>
<target>${java.version}</target>
</configuration>
</plugin>
<!-- Assembly Plugin -->
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<version>3.0.0</version>
<configuration>
<filters>
<filter>src/main/assembly/filter.properties</filter>
</filters>
<descriptors>
<descriptor>src/main/assembly/assembly.xml</descriptor>
</descriptors>
</configuration>
<executions>
<execution>
<id>make-assembly</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
<!-- Jar Plugin -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<configuration>
<classesDirectory>${project.build.directory}/${project.artifactId}-${project.version}-distro</classesDirectory>
<archive>
<manifest>
<mainClass>org.assembly.test.Main</mainClass>
</manifest>
<manifestEntries>
<Plugin-Id>${plugin.id}</Plugin-Id>
<Plugin-Class>${plugin.class}</Plugin-Class>
<Plugin-Version>${plugin.version}</Plugin-Version>
<Plugin-Provider>${plugin.provider}</Plugin-Provider>
<Plugin-Dependencies>${plugin.dependencies}</Plugin-Dependencies>
</manifestEntries>
</archive>
</configuration>
<executions>
<execution>
<id>default-jar</id>
<phase>verify</phase>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
<dependencies>
<!-- https://mvnrepository.com/artifact/org.apache.commons/commons-lang3 -->
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.5</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>
Here I added execution section to maven-jar-plugin to:
<executions>
<execution>
<id>default-jar</id>
<phase>verify</phase>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
It is important to set the id to default-jar, because in this case the default execution is overridden and set the phase to verify for maven-jar-plugin to be executed after maven-assembly-plugin. In case the phase was set to package then maven-jar-plugin was executed before maven-assembly-plugin.
Related
Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.1:compile (default-compile) on project in Jenkins build with error message
[INFO] --- maven-compiler-plugin:3.1:compile (default-compile) # projectname---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 21 source files to C:\Program Files (x86)\Jenkins\workspace\projectname\target\classes
[INFO] -------------------------------------------------------------
[ERROR] COMPILATION ERROR :
[INFO] -------------------------------------------------------------
[ERROR] Source option 5 is no longer supported. Use 7 or later.
[ERROR] Target option 5 is no longer supported. Use 7 or later.
[INFO] 2 errors
[INFO] -------------------------------------------------------------
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 13.958 s
[INFO] Finished at: 2020-07-30T14:53:55+05:45
[INFO] ------------------------------------------------------------------------
Waiting for Jenkins to finish collecting data
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.1:compile (default-compile) on project Projectname: Compilation failure: Compilation failure:
[ERROR] Source option 5 is no longer supported. Use 7 or later.
[ERROR] Target option 5 is no longer supported. Use 7 or later.
[ERROR] -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[JENKINS] Archiving C:\Program Files (x86)\Jenkins\workspace\projectname\pom.xml to projectnamegroup/projectname/0.0.1-SNAPSHOT/projectname-0.0.1-SNAPSHOT.pom
[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/MojoFailureException
channel stopped
Finished: FAILURE
POM Details
<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>projectnameworkgroup</groupId>
<artifactId>projectnameframework</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>projecnameautomation</name>
<url>http://maven.apache.org</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0-M4</version>
<configuration>
<suiteXmlFiles>
<suiteXmlFile>MYtestNG.xml</suiteXmlFile>
</suiteXmlFiles>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<!-- https://mvnrepository.com/artifact/org.seleniumhq.selenium/selenium-java -->
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>3.141.5</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.testng/testng -->
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>6.14.3</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.sikuli/sikuli-api -->
<dependency>
<groupId>org.sikuli</groupId>
<artifactId>sikuli-api</artifactId>
<version>1.2.0</version>
</dependency>
<!-- https://mvnrepository.com/artifact/commons-io/commons-io -->
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.6</version>
</dependency>
<!-- https://mvnrepository.com/artifact/com.assertthat/selenium-shutterbug -->
<dependency>
<groupId>com.assertthat</groupId>
<artifactId>selenium-shutterbug</artifactId>
<version>0.9.3</version>
</dependency>
<!-- https://mvnrepository.com/artifact/log4j/log4j -->
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.17</version>
</dependency>
<!-- https://mvnrepository.com/artifact/mysql/mysql-connector-java -->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.38</version>
</dependency>
<!-- https://mvnrepository.com/artifact/com.opencsv/opencsv -->
<dependency>
<groupId>com.opencsv</groupId>
<artifactId>opencsv</artifactId>
<version>4.0</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.apache.maven.plugins/maven-clean-plugin -->
<dependency>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-clean-plugin</artifactId>
<version>2.5</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.apache.maven.plugins/ -->
<dependency>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
</dependency>
</dependencies>
<repositories>
<repository>
<id>mvntestngrepo.read</id>
<url>https://github.com/abc/projectname</url>
</repository>
</repositories>
</project>
Looking for solution. Please give your valuable solution.Thank you
Used version Details
Looks like maven-compiler-plugin has default 5 source and target options.
You must set explicit values to that options.
Something like this:
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<encoding>UTF-8</encoding>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
I have a multi-module project with java and scala. Both jacoco and scoverage plugins are installed in Jenkins and I want to generate jacoco and scoverage reports (both) in a single build job in Jenkins but only one report is getting generated, either jacoco or scoverage.
Below mvn commands tried so far -
mvn -B -s $MVN_SETTINGS jacoco:prepare-agent install scoverage:report jacoco:report
and
mvn -B -s $MVN_SETTINGS jacoco:prepare-agent install jacoco:report scoverage:report
The snippet of my pom file -
Plugins section -
<plugins>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.7.9</version>
<configuration>
<destFile>./target/jacoco.exec</destFile>
<append>true</append>
</configuration>
<executions>
<execution>
<id>default-prepare-agent</id>
<goals>
<goal>prepare-agent</goal>
</goals>
</execution>
<execution>
<id>default-report</id>
<phase>prepare-package</phase>
<goals>
<goal>report</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.scoverage</groupId>
<artifactId>scoverage-maven-plugin</artifactId>
<version>1.3.0</version>
<configuration>
<scalaVersion>2.10.4</scalaVersion>
<highlighting>true</highlighting>
<aggregate>true</aggregate>
</configuration>
</plugin>
</plugins>
Reporting section -
<reporting>
<outputDirectory>${project.build.directory}/site</outputDirectory>
<plugins>
<plugin>
<groupId>org.scoverage</groupId>
<artifactId>scoverage-maven-plugin</artifactId>
<version>1.3.0</version>
<configuration>
<aggregate>true</aggregate>
</configuration>
<reportSets>
<reportSet>
<reports>
<report>report</report>
</reports>
</reportSet>
</reportSets>
</plugin>
<plugin>
</plugins>
</reporting>
When I use -
mvn -B -s $MVN_SETTINGS jacoco:prepare-agent install scoverage:report jacoco:report
jacoco report gets generated
Build log -
05:30:51 [Compile] [INFO] --- scoverage-maven-plugin:1.3.0:report
(default-cli) # ABC --- 05:30:51 [Compile] [INFO] Reading scoverage
instrumentation
[/workspace/Build-Pipeline/ABC/target/scoverage-data/scoverage.coverage.xml]...
05:30:51 [Compile] [INFO] Reading scoverage measurements
[/workspace/Build-Pipeline/ABC/target/scoverage-data/scoverage.measurements.*]...
05:30:51 [Compile] [INFO] Generating coverage reports... 05:30:51
[Compile] [INFO] Written Cobertura XML report
[/workspace/Build-Pipeline/ABC/target/cobertura.xml] 05:30:52
[Compile] [INFO] Written XML coverage report
[/workspace/Build-Pipeline/ABC/target/scoverage.xml] 05:30:53
[Compile] [INFO] Written HTML coverage report
[/workspace/Build-Pipeline/ABC/target/site/scoverage/index.html]
05:30:53 [Compile] [INFO] Statement coverage.: 0.00% 05:30:53
[Compile] [INFO] Branch coverage....: 0.00% 05:30:53 [Compile] [INFO]
Coverage reports completed.
When I use -
mvn -B -s $MVN_SETTINGS jacoco:prepare-agent install jacoco:report scoverage:report
scoverage report gets generated
Build log -
05:15:07 [Compile] [INFO] --- scoverage-maven-plugin:1.3.0:report
(default-cli) # ABC --- 05:15:07 [Compile] [INFO] Reading scoverage
instrumentation
[/workspace/Build-Pipeline/ABC/target/scoverage-data/scoverage.coverage.xml]...
05:15:07 [Compile] [INFO] Reading scoverage measurements
[/workspace/Build-Pipeline/ABC/target/scoverage-data/scoverage.measurements.*]...
05:15:07 [Compile] [INFO] Generating coverage reports... 05:15:07
[Compile] [INFO] Written Cobertura XML report
[/workspace/Build-Pipeline/ABC/target/cobertura.xml] 05:15:08
[Compile] [INFO] Written XML coverage report
[/workspace/Build-Pipeline/ABC/target/scoverage.xml] 05:15:08
[Compile] [INFO] Written HTML coverage report
[/workspace/Build-Pipeline/ABC/target/site/scoverage/index.html]
05:15:08 [Compile] [INFO] Statement coverage.: 0.00% 05:15:08
[Compile] [INFO] Branch coverage....: 0.00% 05:15:08 [Compile] [INFO]
Coverage reports completed.
Can someone please point me what is going wrong?
Many thanks
Given src/main/java/HelloJava.java
class HelloJava {
public static String msg() {
return "Hello";
}
}
src/main/scala/HelloScala.scala
object HelloScala {
def msg = {
"Hello"
}
}
src/test/java/HelloTest.java
import org.junit.Test;
import static org.junit.Assert.assertEquals;
public class HelloTest {
#Test
public void test() {
assertEquals("Hello", HelloJava.msg());
assertEquals("Hello", HelloScala.msg());
}
}
and pom.xml
<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.example</groupId>
<artifactId>example</artifactId>
<version>0.0.1-SNAPSHOT</version>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>org.scala-lang</groupId>
<artifactId>scala-library</artifactId>
<version>2.11.6</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<version>3.0.0</version>
<executions>
<execution>
<id>add-source</id>
<phase>generate-sources</phase>
<goals>
<goal>add-source</goal>
</goals>
<configuration>
<sources>
<source>src/main/scala</source>
</sources>
</configuration>
</execution>
<execution>
<id>add-test-source</id>
<phase>generate-sources</phase>
<goals>
<goal>add-test-source</goal>
</goals>
<configuration>
<sources>
<source>src/test/scala</source>
</sources>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>net.alchim31.maven</groupId>
<artifactId>scala-maven-plugin</artifactId>
<version>3.4.4</version>
<executions>
<execution>
<goals>
<goal>compile</goal>
<goal>testCompile</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.8.2</version>
<executions>
<execution>
<goals>
<goal>prepare-agent</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.scoverage</groupId>
<artifactId>scoverage-maven-plugin</artifactId>
<version>1.1.1</version>
<configuration>
<highlighting>true</highlighting>
</configuration>
</plugin>
</plugins>
</build>
</project>
execution of mvn clean test jacoco:report scoverage:report
will produce target/site/jacoco/index.html
and target/site/scoverage/index.html
Deploy Spring Cloud project with docker, some code in the pom.xml:
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<!-- tag::plugin[] -->
<plugin>
<groupId>com.spotify</groupId>
<artifactId>docker-maven-plugin</artifactId>
<version>1.0.0</version>
<configuration>
<imageName>${docker.image.prefix}/${project.artifactId}</imageName>
<dockerDirectory>src/main/docker</dockerDirectory>
<resources>
<resource>
<targetPath>/</targetPath>
<directory>${project.build.directory}</directory>
<include>${project.build.finalName}.jar</include>
</resource>
</resources>
</configuration>
</plugin>
<!-- end::plugin[] -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<skipTests>true</skipTests>
</configuration>
</plugin>
</plugins>
</build>
when i run the command: mvn package docker:build, it throws the error:
[INFO]
[INFO] --- spring-boot-maven-plugin:1.5.2.RELEASE:repackage (default) # eureka-server ---
[INFO]
[INFO] --- docker-maven-plugin:1.0.0:build (default-cli) # eureka-server ---
[INFO] Using authentication suppliers: [ConfigFileRegistryAuthSupplier]
[INFO] Copying /Users/eureka-server/target/eureka-server-0.0.1-SNAPSHOT.jar -> /Users/eureka-server/target/docker/eureka-server-0.0.1-SNAPSHOT.jar
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 6.728 s
[INFO] Finished at: 2017-11-15T20:51:07+08:00
[INFO] Final Memory: 41M/361M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal com.spotify:docker-maven-plugin:1.0.0:build (default-cli) on project eureka-server: Exception caught: basedir src/main/docker does not exist -> [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
my project has this file src/main/docker, how to solve it?
To add project path to the dockerDirectory:
<dockerDirectory>${project.basedir}/src/main/docker</dockerDirectory>
pom.xml:
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<!-- tag::plugin[] -->
<plugin>
<groupId>com.spotify</groupId>
<artifactId>docker-maven-plugin</artifactId>
<version>1.0.0</version>
<configuration>
<imageName>${docker.image.prefix}/${project.artifactId}</imageName>
<dockerDirectory>${project.basedir}/src/main/docker</dockerDirectory>
<resources>
<resource>
<targetPath>/</targetPath>
<directory>${project.build.directory}</directory>
<include>${project.build.finalName}.jar</include>
</resource>
</resources>
</configuration>
</plugin>
<!-- end::plugin[] -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<skipTests>true</skipTests>
</configuration>
</plugin>
</plugins>
</build>
I'm using datanucleus/mongodb. I recently converted my dynamic web project to maven in Eclipse because I wanted to use the maven buildnumber plugin. However I am just trying to get it to work now in maven. I do not have issues getting my simple projects to compile and run with Eclipse.
My projects are divided into 3 - main, LibA, LibAA.
Main relies/uses stuff in LibA (or directly from LibAA as well) and LibA relies/uses stuff from LibAA. LibAA doesn't know of other projects.
Example:
LibAA - DObject data class file
LibA - DRemote inherits from DObject
Main - DStaff inherits from DObject
That's how I set the dependencies in Pom xml.
So the issue here is that whenever I tried mvn clean package/install in Main project, I always get symbol not found for the data classes files that inherits from LibAA.
Datanucleus query says DStaff has been renamed to QDStaff, then later further down the process, it says DObject could not be found. Is it because DObject has been internally renamed to QDObject as well, hence it is too late to find them?
2 questions.
1: why is my data files being renamed. I.e a Q character is prependded
2: why am I still getting the symbol not found error despite calling datanucleus enhancer and correctly setting the dependencies? I have no problems with standalone data class files but only those that inherits DObject is the LibAA project.
I seems to have been missing something..
Any insights is appreciated.
edit: added a example partial compile log (with most of the similar errors/log removed)
[INFO] --- maven-compiler-plugin:3.3:compile (default-compile) # MyMainProject ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 591 source files to /Users/rhs/gitnew/MyMainProject/MyMainProject/target/classes
DataNucleus : JDO Query - com.rhs.kms.data.DServerSettingRecord -> com.rhs.kms.data.QDServerSettingRecord
DataNucleus : JDO Query - com.rhs.kms.data.account.DStaffAccount -> com.rhs.kms.data.account.QDStaffAccount
DataNucleus : JDO Query - com.rhs.kms.data.DMenu -> com.rhs.kms.data.QDMenu
[INFO] -------------------------------------------------------------
[ERROR] COMPILATION ERROR :
[INFO] -------------------------------------------------------------
[ERROR] /Users/rhs/gitnew/MyMainProject/MyMainProject/target/generated-sources/annotations/com/rhs/data/account/QDStaffAccount.java:[6,55] cannot find symbol
symbol: class QAuthAccount
location: package com.rhslib.account
[ERROR] /Users/rhs/gitnew/MyMainProject/MyMainProject/target/generated-sources/annotations/com/rhs/data/QDTableOrderingSettings.java:[6,65] cannot find symbol
symbol: class QDObject
location: package com.rhslib.database
[INFO] 10 errors
[INFO] -------------------------------------------------------------
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 19.056 s
[INFO] Finished at: 2015-09-14T16:25:40+08:00
[INFO] Final Memory: 25M/300M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.3:compile (default-compile) on project MyMainProject: Compilation failure: Compilation failure:
[ERROR] /Users/rhs/gitnew/MyMainProject/MyMainProject/target/generated-sources/annotations/com/rhs/data/account/QDStaffAccount.java:[6,55] cannot find symbol
[ERROR] symbol: class QAuthAccount
[ERROR] location: package com.rhslib.account
[ERROR] /Users/rhs/gitnew/MyMainProject/MyMainProject/target/generated-sources/annotations/com/rhs/kms/data/QMenu.java:[6,47] cannot find symbol
[ERROR] symbol: class QDObject
[ERROR] location: package com.rhslib.database
edit2: This is an example of a file where it broke (taken from target/generated-sources/annotations/*)
package com.rhs.data.ARM;
import javax.jdo.query.*;
import org.datanucleus.api.jdo.query.*;
public class QDAccountApp extends com.rhslib.database.QDObject //error starts from QDObject
To iterate, DAccountApp exists in the main project. Main project depends on a lib named KMSLib, and KMSLib depends on a project named RHSLib. I have tried making Main project depend directly with both projects but to no avail.
edit3: attached my pom.xml from my Main project
<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>MainProject</groupId>
<artifactId>MainProject</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>war</packaging>
<name>MainProject</name>
<properties>
<maven.build.timestamp.format>yyyy/MM/dd hh:mm:ss a</maven.build.timestamp.format>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<encoding>UTF-8</encoding>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>
<build>
<sourceDirectory>src</sourceDirectory>
<resources>
<resource>
<directory>src</directory>
<excludes>
<exclude>**/*.java</exclude>
</excludes>
</resource>
</resources>
<plugins>
<plugin>
<groupId>org.datanucleus</groupId>
<artifactId>datanucleus-maven-plugin</artifactId>
<version>4.0.1</version>
<configuration>
<api>JDO</api>
<props>${basedir}/datanucleus.properties</props>
<log4jConfiguration>${basedir}/log4j.properties</log4jConfiguration>
<verbose>true</verbose>
</configuration>
<executions>
<execution>
<phase>process-classes</phase>
<goals>
<goal>enhance</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-war-plugin</artifactId>
<version>2.6</version>
<configuration>
<warSourceDirectory>WebContent</warSourceDirectory>
<failOnMissingWebXml>false</failOnMissingWebXml>
<archive>
<manifest>
<addDefaultSpecificationEntries>false</addDefaultSpecificationEntries>
<addDefaultImplementationEntries>false</addDefaultImplementationEntries>
</manifest>
</archive>
</configuration>
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.3</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>KMSLib</groupId>
<artifactId>KMSLib</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>com.jcabi</groupId>
<artifactId>jcabi-manifests</artifactId>
<version>2.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.jboss.spec.javax.servlet</groupId>
<artifactId>jboss-servlet-api_3.1_spec</artifactId>
<version>1.0.0.Final</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>commons-net</groupId>
<artifactId>commons-net</artifactId>
<version>3.3</version>
</dependency>
<dependency>
<groupId>org.quartz-scheduler</groupId>
<artifactId>quartz</artifactId>
<version>2.2.1</version>
</dependency>
<dependency>
<groupId>javax.json</groupId>
<artifactId>javax.json-api</artifactId>
<version>1.0</version>
</dependency>
<dependency>
<groupId>javax.ejb</groupId>
<artifactId>javax.ejb-api</artifactId>
<version>3.2</version>
</dependency>
<dependency>
<groupId>javax.mail</groupId>
<artifactId>mail</artifactId>
<version>1.5.0-b01</version>
</dependency>
</dependencies>
<repositories>
<repository>
<id>oss.sonatype.org</id>
<url>https://oss.sonatype.org/content/repositories/snapshots/</url>
</repository>
<repository>
<id>maven2-repository.dev.java.net</id>
<name>Java.net Repository for Maven</name>
<url>http://download.java.net/maven/2/</url>
<layout>default</layout>
</repository>
<repository>
<id>DN_M2_Repo</id>
<name>DataNucleus Repository</name>
<url>http://www.datanucleus.org/downloads/maven2</url>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>DataNucleus_2</id>
<url>http://www.datanucleus.org/downloads/maven2/</url>
<snapshots>
<enabled>false</enabled>
</snapshots>
</pluginRepository>
</pluginRepositories>
</project>
edit4: attached my .classpath file
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry including="**/*.java" kind="src" output="target/classes" path="src">
<attributes>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
<attributes>
<attribute name="maven.pomderived" value="true"/>
<attribute name="org.eclipse.jst.component.dependency" value="/WEB-INF/lib"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.jst.server.core.container/org.jboss.ide.eclipse.as.core.server.runtime.runtimeTarget/WildFly 8.x Runtime">
<attributes>
<attribute name="owner.project.facets" value="jst.web"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<classpathentry kind="output" path="target/classes"/>
</classpath>
Hi I have a mvn sub module whose sole purpose is to collect jar's from various other module and create a zip file with all dependencies and configurations.
<parent>
<artifactId>foo</artifactId>
<groupId>com.foo</groupId>
<version>0.1</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>dist</artifactId>
<packaging>pom</packaging>
<name>dist</name>
<url>http://maven.apache.org</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<descriptors>
<descriptor>assembly.xml</descriptor>
</descriptors>
</configuration>
<executions>
<execution>
<id>generate zip</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</pluginManagement>
</build>
Now if I use mvn assembly:assembly it creates the desired zip file. But if I use mvn package it doesn't do any thing i.e. its not creating the zip file. Just gives below output and finishes.
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building dist 0.1
[INFO] ------------------------------------------------------------------------
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 0.120s
[INFO] Finished at: Mon Jul 15 16:34:09 IST 2013
[INFO] Final Memory: 5M/92M
[INFO] ------------------------------------------------------------------------
Any idea on why this is not working. What is that I am missing here.
Thanks for all the help in advance.
As Robert mentioned you have to move out your plugin from plugin-management. Try something like this
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<descriptors>
<descriptor>assembly.xml</descriptor>
</descriptors>
</configuration>
<executions>
<execution>
<id>generate zip</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
Hope this helps
That's not how pluginManagement works. You should define at least as a standard build-plugin.
During a lifecycle, Maven will use its default and it goes through the build-plugins to see if there's a plugin bound to a phase. If it finds a plugin, it will look at the pluginManagement for the same plugin to see if there are some additional configurations.