I stuck on building complex maven multi module project based on Hexagonal architecture.
My maven module structure look like that
| graphql-intro (root module)
| graphql-intro.xml
+-- bootloader (module)
| +--- src/main/java/com/intro/graphql/ApplicationInitializer
| +--- bootloader.xml
|
+-- domain (module)
| +--- domain.xml
|
+-- infrastructure-adapters (module, root module for adapters)
| +--- infrastructure-adapters.xml
|
| +--- adapter-api-graphql (module)
| | +--- adapter-api-graphql.xml
|
| +--- adapter-persistence-in-memory (module)
| | +--- adapter-persistence-in-memory.xml
|
| +--- adapter-persistence-spring-data-jpa (module)
| | +--- adapter-persistence-spring-data-jpa.xml
root.xml look like that
...
<packaging>pom</packaging>
<modules>
<module>domain</module>
<module>infrastructure-adapters</module>
<module>bootloader</module>
</modules>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.2.4.RELEASE</version>
</parent>
<groupId>com.into.graphql</groupId>
<artifactId>graphql-into</artifactId>
<version>0.0.1-SNAPSHOT</version>
...
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>${spring-boot.version}</version>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
<configuration>
<mainClass>com.intro.graphql.ApplicationInitializer</mainClass>
</configuration>
</plugin>
...
and this is infrastructure-adapters.xml
<parent>
<artifactId>graphql-into</artifactId>
<groupId>com.into.graphql</groupId>
<version>0.0.1-SNAPSHOT</version>
</parent>
<packaging>pom</packaging>
<artifactId>infrastructure-adapters</artifactId>
<name>infrastructure-adapters</name>
<description>infrastructure-adapters</description>
<modules>
<module>adapter-persistence-spring-data-jpa</module>
<module>adapter-persistence-in-memory</module>
<module>adapter-api-graphql-kickstarter</module>
</modules>
The problem is that during build persistence adapters cannot see class from domain module, and this is pom in spring data jpa persistence adapter
<parent>
<groupId>com.into.graphql</groupId>
<artifactId>infrastructure-adapters</artifactId>
<version>0.0.1-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>adapter-persistence-spring-data-jpa</artifactId>
<name>adapter-persistence-spring-data-jpa</name>
<description>adapter-persistence-spring-data-jpa</description>
<dependencies>
...
<dependency>
<groupId>com.into.graphql</groupId>
<artifactId>domain</artifactId>
</dependency>
...
</dependencies>
The error is
[INFO] graphql-into ....................................... SUCCESS [ 1.875 s]
[INFO] domain ............................................. SUCCESS [ 2.582 s]
[INFO] infrastructure-adapters ............................ SUCCESS [ 0.092 s]
[INFO] adapter-persistence-spring-data-jpa ................ FAILURE [ 2.118 s]
[INFO] adapter-persistence-in-memory ...................... SKIPPED
[INFO] adapter-api-graphql-kickstarter .................... SKIPPED
[INFO] bootloader ......................................... SKIPPED
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 7.152 s
[INFO] Finished at: 2020-04-30T11:17:26+02:00
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.8.1:compile (default-compile) on project adapter-persistence-spring-data-jpa: Compilation failure: Compilation failure:
[ERROR] path/graphql-into/infrastructure-adapters/adapter-persistence-spring-data-jpa/src/main/java/com/intro/graphql/persistance/jpa/products/ProductDaoAdapter.java:[3,33] package com.intro.grap
hql.dealers does not exist (it is package from domain module)
Has anyone know what could be a problem, can inside module depend from outside module or maybe the order of build is bad ?
Problem solved, I moved build configuration with spring-boot-maven-plugin to the bootloader pom and now build work. Unfortunatelly I dont know the reason why it solved problem.
Related
I know the concept of super pom and inheritance. But still I see extra plugins magically coming up in my child module effective pom.
The project is very simple :
We have 2 POM -one for parent module and one for child module.
Parent module :
<?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>com.practice</groupId>
<artifactId>learning-maven</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>pom</packaging>
<modules>
<module>child-module1</module>
</modules>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<pluginManagement>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</pluginManagement>
<plugins>
<plugin>
<groupId>fr.jcgay.maven.plugins</groupId>
<artifactId>buildplan-maven-plugin</artifactId>
<version>1.3</version>
</plugin>
</plugins>
</build>
</project>
Child module POM :
<?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>
<parent>
<groupId>com.practice</groupId>
<artifactId>learning-maven</artifactId>
<version>1.0-SNAPSHOT</version>
</parent>
<artifactId>child-module1</artifactId>
<version>1.0-SNAPSHOT</version>
</project>
If I generate effective POM of child and parent module I get this :
(I am showing the effective POM data of plugins and goals through buildplan-maven-plugin for ease of reading. I have checked these plugin data with respect to effective POM too.)
[INFO] ------------------------------------------------------------------------
[INFO] Building learning-maven 1.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- buildplan-maven-plugin:1.3:list (default-cli) # learning-maven ---
[INFO] Build Plan for learning-maven:
----------------------------------------------------------
PLUGIN | PHASE | ID | GOAL
----------------------------------------------------------
maven-install-plugin | install | default-install | install
maven-deploy-plugin | deploy | default-deploy | deploy
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building child-module1 1.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- buildplan-maven-plugin:1.3:list (default-cli) # child-module1 ---
[INFO] Build Plan for child-module1:
---------------------------------------------------------------------------------------
PLUGIN | PHASE | ID | GOAL
---------------------------------------------------------------------------------------
maven-resources-plugin | process-resources | default-resources | resources
maven-compiler-plugin | compile | default-compile | compile
maven-resources-plugin | process-test-resources | default-testResources | testResources
maven-compiler-plugin | test-compile | default-testCompile | testCompile
maven-surefire-plugin | test | default-test | test
maven-jar-plugin | package | default-jar | jar
maven-install-plugin | install | default-install | install
maven-deploy-plugin | deploy | default-deploy | deploy
[INFO] ------------------------------------------------------------------------
If you see in child module , you are getting more plugins than the parent.
If you want to see the super POM , it is here.
So where does this extra plugins coming from in child module ?
I do not see it in your child pom, but you probably set the packaging to jar somewhere. The standard lifecycle of Maven defines several goals to be called depending on the packaging, and the Maven plugins you list would fit well to those goals.
I am migrating from ant to maven.
I need to make the environment specific builds for dev and prod, I have seen many questions related to that but in my case I have some java files which will only goes into prod. How can I use those java fils to separate the builds.
my project structure looks like
parent
project A
| src
| pom
project B
| src
| pom
project C
| src
| pom
project D
| src
| pom
Parent-POM
Java files which are only used in Prod are the password utilities files.
Please let me know if you have any confusion.
Thanks in advance.
I agree with #khmarbaise, nevertheless a dirty approach could be to define the library name as a property and use 2 different profile to decide with library to use.
<dependencies>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>${slf4j.version}</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>${my.library}</artifactId>
<version>${slf4j.version}</version>
</dependency>
</dependencies>
<properties>
<slf4j.version>1.7.25</slf4j.version>
</properties>
<profiles>
<profile>
<id>prod</id>
<properties>
<my.library>slf4j-jdk14</my.library>
</properties>
</profile>
<profile>
<id>dev</id>
<properties>
<my.library>slf4j-log4j12</my.library>
</properties>
</profile>
</profiles>
mvn -P dev dependency:tree
[INFO] --- maven-dependency-plugin:2.8:tree (default-cli) # test ---
[INFO] test:test:jar:1.0-SNAPSHOT
[INFO] +- org.slf4j:slf4j-api:jar:1.7.25:compile
[INFO] \- org.slf4j:slf4j-log4j12:jar:1.7.25:compile
[INFO] \- log4j:log4j:jar:1.2.17:compile
[
mvn -P prod dependency:tree
[INFO] --- maven-dependency-plugin:2.8:tree (default-cli) # test ---
[INFO] test:test:jar:1.0-SNAPSHOT
[INFO] +- org.slf4j:slf4j-api:jar:1.7.25:compile
[INFO] \- org.slf4j:slf4j-jdk14:jar:1.7.25:compile
[
Collegues, i have subproject utils in my multimodule project. The pom looks like:
<?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">
<parent>
<artifactId>parent</artifactId>
<groupId>com.comp.kort</groupId>
<version>1.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>utils</artifactId>
<dependencies>
<dependency>
<groupId>com.sun.mail</groupId>
<artifactId>javax.mail</artifactId>
<version>1.5.5</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.3</version>
<configuration>
<source>${project.build.sourceJdk}</source>
<target>${project.build.targetJdk}</target>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
</plugins>
</build>
</project>
I run command mvn clean install and utils-1.0-SNAPSHOT.jar is created in the local maven repository.
After that i add next dependency into pom of another subproject
<dependency>
<groupId>com.comp.kort</groupId>
<artifactId>utils</artifactId>
<version>1.0-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
But when i add import com.comp.kort to classes of my second subproject i receive Can't resolve symbol 'kort'.
What should i to import com.comp.kort in the second subproject correctly?
mvn dependency:tree on my second subproject shows:
[INFO] com.comp.kort:kort-sp-integration:jar:1.0-SNAPSHOT
[INFO] +- org.springframework.batch:spring-batch-core:jar:3.0.7.RELEASE:compile
[INFO] | +- com.ibm.jbatch:com.ibm.jbatch-tck-spi:jar:1.0:compile
[INFO] | | \- javax.batch:javax.batch-api:jar:1.0:compile
[INFO] | +- com.thoughtworks.xstream:xstream:jar:1.4.7:compile
[INFO] | | +- xmlpull:xmlpull:jar:1.1.3.1:compile
[INFO] | | \- xpp3:xpp3_min:jar:1.1.4c:compile
[INFO] | +- org.codehaus.jettison:jettison:jar:1.2:compile
[INFO] | +- org.springframework.batch:spring-batch-infrastructure:jar:3.0.7.RELEASE:compile
[INFO] | | \- org.springframework.retry:spring-retry:jar:1.1.0.RELEASE:compile
[INFO] | +- org.springframework:spring-aop:jar:4.0.5.RELEASE:compile
[INFO] | | \- aopalliance:aopalliance:jar:1.0:compile
[INFO] | +- org.springframework:spring-beans:jar:4.0.5.RELEASE:compile
[INFO] | +- org.springframework:spring-context:jar:4.0.5.RELEASE:compile
[INFO] | | \- org.springframework:spring-expression:jar:4.0.5.RELEASE:compile
[INFO] | +- org.springframework:spring-core:jar:4.0.5.RELEASE:compile
[INFO] | \- org.springframework:spring-tx:jar:4.0.5.RELEASE:compile
[INFO] +- org.springframework:spring-jdbc:jar:4.2.6.RELEASE:compile
[INFO] +- org.apache.commons:commons-dbcp2:jar:2.1.1:compile
[INFO] | +- org.apache.commons:commons-pool2:jar:2.4.2:compile
[INFO] | \- commons-logging:commons-logging:jar:1.2:compile
[INFO] +- commons-io:commons-io:jar:2.2:compile
[INFO] +- log4j:log4j:jar:1.2.17:compile
[INFO] +- com.microsoft.sqlserver:sqljdbc4:jar:4.2:compile
[INFO] +- org.apache.commons:commons-lang3:jar:3.4:compile
[INFO] +- junit:junit:jar:4.12:test
[INFO] | \- org.hamcrest:hamcrest-core:jar:1.3:test
[INFO] +- com.sun.mail:javax.mail:jar:1.5.5:compile
[INFO] | \- javax.activation:activation:jar:1.1:compile
[INFO] \- com.comp.kort:utils:jar:1.0-SNAPSHOT:compile
It seems <scope>provided</scope> is not right, and you can remove it.
Provided is much like compile, but indicates you expect the JDK or a container to provide the dependency at runtime. For example, when building a web application for the Java Enterprise Edition, you would set the dependency on the Servlet API and related Java EE APIs to scope provided because the web container provides those classes. This scope is only available on the compilation and test classpath, and is not transitive.
You can see here
I need some help with trying to get an executable working. This is a tricky one and I've narrowed it down to the fact that something is different with the way that maven exec runs things and how either the maven shade plugin or the maven assembly plugin is packaging the files.
I'm building a REST service in Java with Netty and JAX-RS and use Jackson to translate from POJOs to JSON.
The server starts up correctly when executing either mvn exec:java or java -jar. But when making a request against the java -jar file, I get the following error:
Could not find MessageBodyWriter for response object of type: [Ljava.lang.Object; of media type: application/json
It seems like something isn't being packaged correctly, but I'm not sure what. Transitive dependencies are missing, maybe?
Here's my POM:
<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>com.test.myserver</groupId>
<artifactId>myserver</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
<name>myserver</name>
<url>http://maven.apache.org</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<repositories>
<repository>
<id>oss-sonatype</id>
<name>oss-sonatype</name>
<url>https://oss.sonatype.org/content/repositories/snapshots/</url>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
</repositories>
<build>
<plugins>
<!-- For executing in maven itself (mvn exec:java) -->
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.2.1</version>
<executions>
<execution>
<goals>
<goal>java</goal>
</goals>
</execution>
</executions>
<configuration>
<mainClass>com.test.myserver.App</mainClass>
</configuration>
</plugin>
<plugin>
<!-- for packaging (mvn package) -->
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>2.2</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<transformers>
<transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<mainClass>com.test.myserver.App</mainClass>
</transformer>
</transformers>
</configuration>
</execution>
</executions>
</plugin>
<!-- The configuration of maven-assembly-plugin -->
<plugin>
<!-- for packaging (mvn compile assembly:single) -->
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.4</version>
<!-- The configuration of the plugin -->
<configuration>
<archive>
<manifest>
<mainClass>com.test.myserver.App</mainClass>
</manifest>
</archive>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>LATEST</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.googlecode.plist</groupId>
<artifactId>dd-plist</artifactId>
<version>LATEST</version>
</dependency>
<!-- MongoDB -->
<dependency>
<groupId>org.mongodb</groupId>
<artifactId>mongo-java-driver</artifactId>
<version>2.12.0</version>
</dependency>
<dependency>
<groupId>org.mongojack</groupId>
<artifactId>mongojack</artifactId>
<version>2.1.0-SNAPSHOT</version>
</dependency>
<!-- REST Server -->
<dependency>
<groupId>org.jboss.resteasy</groupId>
<artifactId>resteasy-jaxrs</artifactId>
<version>LATEST</version>
</dependency>
<dependency>
<groupId>org.jboss.resteasy</groupId>
<artifactId>resteasy-netty</artifactId>
<version>LATEST</version>
</dependency>
<dependency>
<groupId>org.jboss.resteasy</groupId>
<artifactId>resteasy-jackson2-provider</artifactId>
<version>LATEST</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>LATEST</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
<version>LATEST</version>
</dependency>
<dependency>
<groupId>org.reflections</groupId>
<artifactId>reflections</artifactId>
<version>LATEST</version>
</dependency>
</dependencies>
Maven shade is executed with mvn package.
Maven assembly is executed with mvn compile assembly:single.
Thanks in advance!
EDIT
I checked mvn dependency:tree against the output for mvn shade and for all intents, they look the same.
Output from dependency tree
$ mvn dependency:tree
[INFO] Scanning for projects...
[INFO]
[INFO] Using the builder org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder with a thread count of 1
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building myserver 1.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-dependency-plugin:2.8:tree (default-cli) # myserver ---
[INFO] com.test.myserver:myserver:jar:1.0-SNAPSHOT
[INFO] +- junit:junit:jar:4.11:test
[INFO] | \- org.hamcrest:hamcrest-core:jar:1.3:test
[INFO] +- com.googlecode.plist:dd-plist:jar:1.8:compile
[INFO] +- org.mongodb:mongo-java-driver:jar:2.12.0:compile
[INFO] +- org.mongojack:mongojack:jar:2.1.0-SNAPSHOT:compile
[INFO] | +- com.fasterxml.jackson.core:jackson-databind:jar:2.2.3:compile
[INFO] | +- de.undercouch:bson4jackson:jar:2.2.0:compile
[INFO] | +- javax.persistence:persistence-api:jar:1.0.2:compile
[INFO] | \- commons-io:commons-io:jar:2.4:compile
[INFO] +- org.jboss.resteasy:resteasy-jaxrs:jar:3.0.8.Final:compile
[INFO] | +- org.jboss.resteasy:jaxrs-api:jar:3.0.8.Final:compile
[INFO] | +- org.jboss.spec.javax.annotation:jboss-annotations-api_1.1_spec:jar:1.0.1.Final:compile
[INFO] | +- javax.activation:activation:jar:1.1:compile
[INFO] | +- org.apache.httpcomponents:httpclient:jar:4.2.1:compile
[INFO] | | +- org.apache.httpcomponents:httpcore:jar:4.2.1:compile
[INFO] | | +- commons-logging:commons-logging:jar:1.1.1:compile
[INFO] | | \- commons-codec:commons-codec:jar:1.6:compile
[INFO] | \- net.jcip:jcip-annotations:jar:1.0:compile
[INFO] +- org.jboss.resteasy:resteasy-netty:jar:3.0.8.Final:compile
[INFO] | \- io.netty:netty:jar:3.6.4.Final:compile
[INFO] +- org.jboss.resteasy:resteasy-jackson2-provider:jar:3.0.8.Final:compile
[INFO] | +- com.fasterxml.jackson.core:jackson-core:jar:2.3.2:compile
[INFO] | +- com.fasterxml.jackson.core:jackson-annotations:jar:2.3.2:compile
[INFO] | \- com.fasterxml.jackson.jaxrs:jackson-jaxrs-json-provider:jar:2.3.2:compile
[INFO] | +- com.fasterxml.jackson.jaxrs:jackson-jaxrs-base:jar:2.3.2:compile
[INFO] | \- com.fasterxml.jackson.module:jackson-module-jaxb-annotations:jar:2.3.2:compile
[INFO] +- org.slf4j:slf4j-api:jar:1.7.7:compile
[INFO] +- org.slf4j:slf4j-simple:jar:1.7.7:compile
[INFO] \- org.reflections:reflections:jar:0.9.9-RC1:compile
[INFO] +- com.google.guava:guava:jar:11.0.2:compile
[INFO] | \- com.google.code.findbugs:jsr305:jar:1.3.9:compile
[INFO] +- org.javassist:javassist:jar:3.16.1-GA:compile
[INFO] \- dom4j:dom4j:jar:1.6.1:compile
[INFO] \- xml-apis:xml-apis:jar:1.0.b2:compile
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1.999 s
[INFO] Finished at: 2014-04-22T17:09:47-08:00
[INFO] Final Memory: 13M/310M
[INFO] ------------------------------------------------------------------------
Output from shade
$ mvn package
[INFO]
[INFO] --- maven-jar-plugin:2.4:jar (default-jar) # myserver ---
[INFO] Building jar: /myserver/target/myserver-1.0-SNAPSHOT.jar
[INFO]
[INFO] --- maven-shade-plugin:2.2:shade (default) # myserver ---
[INFO] Including com.googlecode.plist:dd-plist:jar:1.8 in the shaded jar.
[INFO] Including org.mongodb:mongo-java-driver:jar:2.12.0 in the shaded jar.
[INFO] Including org.mongojack:mongojack:jar:2.1.0-SNAPSHOT in the shaded jar.
[INFO] Including com.fasterxml.jackson.core:jackson-databind:jar:2.2.3 in the shaded jar.
[INFO] Including de.undercouch:bson4jackson:jar:2.2.0 in the shaded jar.
[INFO] Including javax.persistence:persistence-api:jar:1.0.2 in the shaded jar.
[INFO] Including commons-io:commons-io:jar:2.4 in the shaded jar.
[INFO] Including org.jboss.resteasy:resteasy-jaxrs:jar:3.0.8.Final in the shaded jar.
[INFO] Including org.jboss.resteasy:jaxrs-api:jar:3.0.8.Final in the shaded jar.
[INFO] Including org.jboss.spec.javax.annotation:jboss-annotations-api_1.1_spec:jar:1.0.1.Final in the shaded jar.
[INFO] Including javax.activation:activation:jar:1.1 in the shaded jar.
[INFO] Including org.apache.httpcomponents:httpclient:jar:4.2.1 in the shaded jar.
[INFO] Including org.apache.httpcomponents:httpcore:jar:4.2.1 in the shaded jar.
[INFO] Including commons-logging:commons-logging:jar:1.1.1 in the shaded jar.
[INFO] Including commons-codec:commons-codec:jar:1.6 in the shaded jar.
[INFO] Including net.jcip:jcip-annotations:jar:1.0 in the shaded jar.
[INFO] Including org.jboss.resteasy:resteasy-netty:jar:3.0.8.Final in the shaded jar.
[INFO] Including io.netty:netty:jar:3.6.4.Final in the shaded jar.
[INFO] Including org.jboss.resteasy:resteasy-jackson2-provider:jar:3.0.8.Final in the shaded jar.
[INFO] Including com.fasterxml.jackson.core:jackson-core:jar:2.3.2 in the shaded jar.
[INFO] Including com.fasterxml.jackson.core:jackson-annotations:jar:2.3.2 in the shaded jar.
[INFO] Including com.fasterxml.jackson.jaxrs:jackson-jaxrs-json-provider:jar:2.3.2 in the shaded jar.
[INFO] Including com.fasterxml.jackson.jaxrs:jackson-jaxrs-base:jar:2.3.2 in the shaded jar.
[INFO] Including com.fasterxml.jackson.module:jackson-module-jaxb-annotations:jar:2.3.2 in the shaded jar.
[INFO] Including org.slf4j:slf4j-api:jar:1.7.7 in the shaded jar.
[INFO] Including org.slf4j:slf4j-simple:jar:1.7.7 in the shaded jar.
[INFO] Including org.reflections:reflections:jar:0.9.9-RC1 in the shaded jar.
[INFO] Including com.google.guava:guava:jar:11.0.2 in the shaded jar.
[INFO] Including com.google.code.findbugs:jsr305:jar:1.3.9 in the shaded jar.
[INFO] Including org.javassist:javassist:jar:3.16.1-GA in the shaded jar.
[INFO] Including dom4j:dom4j:jar:1.6.1 in the shaded jar.
[INFO] Including xml-apis:xml-apis:jar:1.0.b2 in the shaded jar.
[INFO] Replacing original artifact with shaded artifact.
[INFO] Replacing /myserver/target/myserver-1.0-SNAPSHOT.jar with /myserver/target/myserver-1.0-SNAPSHOT-shaded.jar
[INFO] Dependency-reduced POM written at: /myserver/dependency-reduced-pom.xml
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 4.658 s
[INFO] Finished at: 2014-04-22T17:05:50-08:00
[INFO] Final Memory: 39M/310M
[INFO] ------------------------------------------------------------------------
The shade plugin configuration is missing the service transformer which merges the META-INF/services files used by the service discovery mechanism.
Here is an example:
<transformers>
<transformer implementation="org.apache.maven.plugins.shade.resource.ServicesResourceTransformer" />
<transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<mainClass>com.example.helloworld.HelloWorldApplication</mainClass>
</transformer>
</transformers>
It's interesting because I asked myself the question yesterday, "why do I need an über jar?" And, as it turns out, I don't and probably shouldn't be using an über jar. Alexey correctly answered the question to solve the immediate problem, but I also wanted to post an alternate solution that I figured out for doing things a little bit differently.
Rather than using the shade plugin to build an über jar, I decided to create a standard jar and export all the dependencies needed to run my application. This means that I now use the Maven Jar Plugin to create my jar and the Maven Dependency Plugin to export the libraries. Here's what the build section of the pom.xml looks like:
<build>
<plugins>
<!-- For copying the libraries to the output directory -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>2.8</version>
<executions>
<execution>
<id>copy-dependencies</id>
<phase>package</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<outputDirectory>${project.build.directory}/lib</outputDirectory>
<overWriteReleases>false</overWriteReleases>
<overWriteSnapshots>false</overWriteSnapshots>
<overWriteIfNewer>true</overWriteIfNewer>
</configuration>
</execution>
</executions>
</plugin>
<!-- Create the executable jar -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.4</version>
<configuration>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<classpathPrefix>lib/</classpathPrefix>
<mainClass>com.test.myserver.App</mainClass>
<useUniqueVersions>false</useUniqueVersions>
</manifest>
</archive>
</configuration>
</plugin>
</plugins>
</build>
Since my output directory is target/, my jar is generated as target/myserver-1.0-SNAPSHOT.jar and all the dependencies are in target/lib/. The maven-jar-plugin also build the classpath and points them correctly to the lib/ directory, so I'm pretty much set. This also makes it easier in the future to replace individual libraries as they are updated, rather than uploading an entirely new jar.
Building the jar and copying the dependencies is simply mvn install from the command line.
I'm converting in maven an old project that originally rely on eclipse and ant to build.
Stated that I can't chancge the directory layout of that project, I would like to produce some artifact similar to ones build with that ant script. The original project, build all classes with from subprojects in one directory with eclipse, then package the resulting classes with ant in subpackages (different from subprojects).
To deal with this requirements I've done the following structure: (as now only one of the subpackage)
warp-parent
|
|- pom.xml
|- warp-client
| |
| | - pom.xml
the parent pom is the following:
<?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>it.sinesy.warp</groupId>
<artifactId>warp-parent</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>pom</packaging>
<name>warp-parent</name>
<url>http://maven.apache.org</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<version>1.8</version>
<executions>
<execution>
<id>add-source</id>
<phase>generate-sources</phase>
<goals>
<goal>add-source</goal>
</goals>
<configuration>
<sources>
<source>../../src</source>
<source>../../srcj2ee</source>
<source>../../srcjsf</source>
<source>../../srcrest</source>
<source>../../srcswing</source>
<source>../../srctest</source>
<source>../../srcweb</source>
<source>../../srcws</source>
</sources>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
<dependencies>
</dependencies>
<modules>
<module>warp-client</module>
</modules>
</project>
and the child one:
<?xml version="1.0"?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>it.sinesy.warp</groupId>
<artifactId>warp-parent</artifactId>
<version>1.0-SNAPSHOT</version>
</parent>
<groupId>it.sinesy.warp</groupId>
<artifactId>warp-client</artifactId>
<version>1.0-SNAPSHOT</version>
<name>warp-client</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-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<includes>
<include>**</include>
<!--
<include>**/it/tinet/warp/swing/**/java/*</include>
<include>**/it/tinet/warp/common/**/java/*</include>
<include>**/it/tinet/warp/swing/**/client/*</include> -->
</includes>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
</dependencies>
</project>
When I try to compile to compile the parent pom I got the following output, with no source compiled:
[INFO] Scanning for projects...
[INFO] ------------------------------------------------------------------------
[INFO] Reactor Build Order:
[INFO]
[INFO] warp-parent
[INFO] warp-client
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building warp-parent 1.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- build-helper-maven-plugin:1.8:add-source (add-source) # warp-parent ---
[INFO] Source directory: /home/elettronik/test/warp/warp_src/src added.
[INFO] Source directory: /home/elettronik/test/warp/warp_src/srcj2ee added.
[INFO] Source directory: /home/elettronik/test/warp/warp_src/srcjsf added.
[INFO] Source directory: /home/elettronik/test/warp/warp_src/srcrest added.
[INFO] Source directory: /home/elettronik/test/warp/warp_src/srcswing added.
[INFO] Source directory: /home/elettronik/test/warp/warp_src/srctest added.
[INFO] Source directory: /home/elettronik/test/warp/warp_src/srcweb added.
[INFO] Source directory: /home/elettronik/test/warp/warp_src/srcws added.
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building warp-client 1.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- build-helper-maven-plugin:1.8:add-source (add-source) # warp-client ---
[INFO] Source directory: /home/elettronik/test/warp/warp_src/mvn/src added.
[INFO] Source directory: /home/elettronik/test/warp/warp_src/mvn/srcj2ee added.
[INFO] Source directory: /home/elettronik/test/warp/warp_src/mvn/srcjsf added.
[INFO] Source directory: /home/elettronik/test/warp/warp_src/mvn/srcrest added.
[INFO] Source directory: /home/elettronik/test/warp/warp_src/mvn/srcswing added.
[INFO] Source directory: /home/elettronik/test/warp/warp_src/mvn/srctest added.
[INFO] Source directory: /home/elettronik/test/warp/warp_src/mvn/srcweb added.
[INFO] Source directory: /home/elettronik/test/warp/warp_src/mvn/srcws added.
[INFO]
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) # warp-client ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory /home/elettronik/test/warp/warp_src/mvn/warp-parent/warp-client/src/main/resources
[INFO]
[INFO] --- maven-compiler-plugin:3.1:compile (default-compile) # warp-client ---
[INFO] No sources to compile
[INFO] ------------------------------------------------------------------------
[INFO] Reactor Summary:
[INFO]
[INFO] warp-parent ....................................... SUCCESS [0.762s]
[INFO] warp-client ....................................... SUCCESS [1.389s]
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 2.389s
[INFO] Finished at: Fri Aug 16 14:03:32 CEST 2013
[INFO] Final Memory: 6M/109M
[INFO] ------------------------------------------------------------------------
Could someone give some advice to make this work? thanks to all.
Your parent-pom shows <packaging>pom</packaging> so the sources you define in the parent pom will not be compiled.