I am trying to transform a working single GWT-Project into several Maven-Modules.
New structure should look like this:
Project
|- pom.xml
|- Project-Common(only Common-Classes)
|--- pom.xml
|--- Packaging: jar
|- Project-War(includes *gwt.xml)
|--- pom.xml
|--- Packaging: war
My files look like this(many dependencies, I think i removed the unnecessary to make my problem more clear)
Project pom.xml:
<modelVersion>4.0.0</modelVersion>
<artifactId>project</artifactId>
<packaging>pom</packaging>
<name>Project - Modules</name>
<version>1.0.0-SNAPSHOT</version>
<parent>
<groupId>com.project</groupId>
<artifactId>project-parent-parent</artifactId>
<version>2.0.0</version>
<relativePath />
</parent>
<modules>
<module>/project-war</module>
<module>/project-common</module>
</modules>
Project-Common pom.xml:
<modelVersion>4.0.0</modelVersion>
<artifactId>project-common</artifactId>
<packaging>jar</packaging>
<name>Project - Common</name>
<version>1.0.0-SNAPSHOT</version>
<parent>
<groupId>com.project</groupId>
<artifactId>project-parent</artifactId>
<version>1.0.0-SNAPSHOT</version>
<relativePath />
</parent>
<build>
<plugins>
<plugin>
<groupId>com.github.koraktor</groupId>
<artifactId>mavanagaiata</artifactId>
<executions>
<execution>
<id>load-git-branch</id>
<phase>validate</phase>
<goals>
<goal>commit</goal>
</goals>
<configuration>
<dirtyFlag>*</dirtyFlag>
<gitDir>../../.git</gitDir>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
Project-War pom.xml:
<modelVersion>4.0.0</modelVersion>
<artifactId>project-war</artifactId>
<version>1.1.0-SNAPSHOT</version>
<packaging>war</packaging>
<name>Project - WAR</name>
<parent>
<groupId>com.project</groupId>
<artifactId>parent-project</artifactId>
<version>1.0.0-SNAPSHOT</version>
</parent>
<dependencies>
<dependency>
<groupId>com.project</groupId>
<artifactId>project-common</artifactId>
<version>1.0.0-SNAPSHOT</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>gwt-maven-plugin</artifactId>
<version>2.7.0</version>
<inherited>true</inherited>
<configuration>
<runTarget>/test.html</runTarget>
<modules>
<module>com.project.modules.Test</module>
</modules>
</configuration>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.2.1</version>
<executions>
<execution>
<phase>process-classes</phase>
<goals>
<goal>exec</goal>
</goals>
<configuration>
<id>VerifyRequestFactoryInterfaces</id>
<executable>java</executable>
<arguments>
<argument>-cp</argument>
<classpath />
<argument>com.google.web.bindery.requestfactory.apt.ValidationTool</argument>
<argument>${project.build.outputDirectory}</argument>
<argument>com.project.factorys.TestRequestFactory</argument>
</arguments>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-clean-plugin</artifactId>
<version>2.4.1</version>
<configuration>
<filesets>
<fileset>
<directory>src/main</directory>
<includes>
<directory>gwt-unitCache/**</directory>
</includes>
</fileset>
</filesets>
</configuration>
</plugin>
<plugin>
<groupId>com.github.koraktor</groupId>
<artifactId>mavanagaiata</artifactId>
<executions>
<execution>
<id>load-git-branch</id>
<phase>validate</phase>
<goals>
<goal>commit</goal>
</goals>
<configuration>
<dirtyFlag>*</dirtyFlag>
<gitDir>../../.git</gitDir>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
The old Project was in my Project-War and I added Project & Project-Common. In this setup the Project builds and I get the "new" Project-War.war .
But when I move a ErrorCode.java from Project-War to Project-Common I get the following Error:
[INFO] Tracing compile failure path for type 'com.project.modules.TestViewImpl'
[INFO] [ERROR] Errors in '.../project/project-war/src/main/java/com/project/modules/TestViewImpl.java'
[INFO] [ERROR] Line 20: No source code is available for type com.project.errorcodes.ErrorCode; did you forget to inherit a required module?
[INFO] [ERROR] Hint: Check the inheritance chain from your module; it may not be inheriting a required module or a module may not be adding its source path entries properly
Your Project-Common doesn't package its sources to be available to the Project-War, so GWT effectively can't find the source for ErrorCodes class.
You have to either use the maven-source-plugin's jar-no-fork goal in Project-Common to package sources, and then add a second dependency on Project-Common in Project-War with <classifier>sources</classifier>; or declare your src/main/java as a resource directory to package sources into the Project-Common's JAR.
As a side note, Mojo's Maven Plugin for GWT isn't a great fit for multi-module projects. I'd advise switching to the net.ltgt.gwt.maven:gwt-maven-plugin which was designed for multi-module builds from the ground up (disclaimer: I'm the author of that plugin, and former maintainer of Mojo's plugin)
Found a Solution:
Added a Module in Common-Project
<module>
<inherits name='com.google.gwt.activity.Activity' />
<inherits name='com.google.gwt.place.Place' />
<inherits name="com.google.gwt.user.User" />
<inherits name='com.google.web.bindery.requestfactory.RequestFactory' />
<inherits name="com.google.gwt.user.cellview.CellView" />
<inherits name='com.google.gwt.logging.Logging' />
<inherits name="com.google.gwt.inject.Inject" />
<inherits name="com.google.gwt.text.Text" />
<inherits name="com.google.gwt.i18n.I18N" />
<inherits name="com.google.gwt.debug.Debug" />
<source path="shared"/>
</module>
any my ErrorCode.java is under Path shared/** .
In Project-War Modules I added <inherits name="com.project.Common" /> and in pom.xml from Project-War:
<dependency>
<groupId>com.project</groupId>
<artifactId>project-common</artifactId>
<version>1.0.0-SNAPSHOT</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>com.project</groupId>
<artifactId>project-common</artifactId>
<version>1.0.0-SNAPSHOT</version>
<classifier>sources</classifier>
<scope>provided</scope>
</dependency>
Seems to need dependency with classifier in scope provided.
Related
I have created a web application based on angular 8 and spring boot. I implemented the codebase locally and it is working fine.
My Angular code(client) is running on localhost:4200 and spring boot(server) is running on localhost:8080.
Till here everything is working as expected.
Now I want to deploy this whole web application as a single bundle so that I can deploy it as a single war on tomcat.
I am creating the war file using maven.
But when I deploy this war file on tomcat and start the tomcat I am not able to see the expected login page on the browser.
Basically, I don't have much understanding of maven and was following resource available in below link on the internet to generate the war file.
https://dzone.com/articles/building-a-web-app-using-spring-boot-angular-6-and
So I am not able to figure out whether the issue is with my build or the URL through which I am trying to access the resources.
if I deploy only the UI build, then if I hit localhost:8080, I am able to see the login page.
I am having three pom files as mentioned in the tutorial.
1. parent-pom
2. server-pom
3. ui-pom
Below are my pom files
parent-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 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.dzs.licenseGenerator</groupId>
<artifactId>lg-parent</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>pom</packaging>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.6.RELEASE</version>
<relativePath />
</parent>
<modules>
<module>LicenseGenerator_Backend</module>
<module>LicenseGenerator_UI</module>
</modules>
</project>
server-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 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.dzs.licenseGenerator</groupId>
<artifactId>lg-parent</artifactId>
<version>0.0.1-SNAPSHOT</version>
<!-- lookup parent from repository -->
</parent>
<artifactId>LicenseGenerator_Backend</artifactId>
<packaging>war</packaging>
<properties>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<scope>runtime</scope>
<optional>true</optional>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.dzs.licenseGenerator</groupId>
<artifactId>LicenseGenerator_UI</artifactId>
<version>${project.version}</version>
<scope>runtime</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<executions>
<execution>
<id>copy-resources</id>
<phase>validate</phase>
<goals><goal>copy-resources</goal></goals>
<configuration>
<tasks>
<echo>Displaying value of pom.xml element</echo>
<echo>[project.build.directory] ${project.build.directory}</echo>
<echo>[project.parent.basedir] ${project.parent.basedir}</echo>
</tasks>
<outputDirectory>${project.build.directory}/classes/resources/</outputDirectory >
<resources>
<resource>
<directory>${project.parent.basedir}/LicenseGenerator_UI/dist/lg-app/</directory >
</resource>
</resources>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<configuration>
<packagingExcludes>WEB-INF/lib/tomcat-*.jar</packagingExcludes>
<warName>lg-app</warName>
</configuration>
</plugin>
</plugins>
</build>
</project>
UI-pom.xml
<?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>com.dzs.licenseGenerator</groupId>
<artifactId>lg-parent</artifactId>
<version>0.0.1-SNAPSHOT</version>
</parent>
<artifactId>LicenseGenerator_UI</artifactId>
<name>LicenseGenerator_UI</name>
<url>http://maven.apache.org</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<build>
<plugins>
<plugin>
<groupId>com.github.eirslett</groupId>
<artifactId>frontend-maven-plugin</artifactId>
<version>1.4</version>
<configuration>
<nodeVersion>v10.16.0</nodeVersion>
<npmVersion>6.9.0</npmVersion>
<workingDirectory>src/main/web/</workingDirectory>
</configuration>
<executions>
<execution>
<id>install node and npm</id>
<goals>
<goal>install-node-and-npm</goal>
</goals>
</execution>
<execution>
<id>npm install</id>
<goals>
<goal>npm</goal>
</goals>
</execution>
<execution>
<id>npm run build</id>
<goals>
<goal>npm</goal>
</goals>
<configuration>
<arguments>run build</arguments>
</configuration>
</execution>
<execution>
<id>prod</id>
<goals>
<goal>npm</goal>
</goals>
<configuration>
<arguments>run-script build</arguments>
</configuration>
<phase>generate-resources</phase>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
Just to ensure whether my code structure is correct or not I am posting a screenshot of my Project Explorer in Eclipse.
Use ng build –prod command for generating production build artifacts.
Run this command in your UI project folder.
Post generation of production build you should see new folder named ‘dist’.
You have to use Maven resource plugin to package as single jar. As i can see you already have the plugin in you pom, just verify the directory folder to pint to dist folder.
After this just run maven clean install . After running this you should see jar with both Angular 6 & Spring Boot application on the target folder.
Execute with Java –jar command to launch the application, you should see the Angular application served from static folder.
You can use frontend-maven-plugin for kicking off your frontend build. Once the frontend build is completed, it will generate the resource files in dist directory.
After that you can use the maven-resources-plugin to copy the files from dist to the required location in the target directory.
I am trying to build a single uber-jar from a set a modules that are mostly independent, but it's not working the way I'd thought.
I was initially directed here: https://maven.apache.org/plugins/maven-assembly-plugin/examples/multimodule/module-binary-inclusion-simple.html though now I'm not quite certain that this was what I should have started with...
The parent pom file looks like this:
<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.mycompany</groupId>
<artifactId>BigProject</artifactId>
<version>0.0.1</version>
<packaging>pom</packaging>
<name>BigProject</name>
<modules>
<module>../mod1</module>
<module>../mod2</module>
<!-- ...a bunch more... -->
<module>../distribution</module>
</modules>
<build>
<pluginManagement>
<plugins>
<!-- not even sure why this needs to be specified here, but the documentation seems to think it's important... -->
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<version>3.1.0</version>
<configuration>
<descriptors>
<descriptor>src/assembly/assembly.xml</descriptor>
</descriptors>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>
</project>
The pom for the "distribution" module looks like this:
<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>
<artifactId>distribution</artifactId>
<name>distribution</name>
<packaging>pom</packaging>
<parent>
<groupId>com.mycompany</groupId>
<artifactId>BigProject</artifactId>
<version>0.0.1</version>
</parent>
<build>
<plugins>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<version>3.1.0</version>
<executions>
<execution>
<id>distro-assembly</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
<configuration>
<descriptors>
<descriptor>src/assembly/assembly.xml</descriptor>
</descriptors>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
And finally, the assembly file:
<assembly xmlns="http://maven.apache.org/ASSEMBLY/2.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/ASSEMBLY/2.0.0 http://maven.apache.org/xsd/assembly-2.0.0.xsd">
<id>bin</id>
<formats>
<format>dir</format>
</formats>
<includeBaseDirectory>false</includeBaseDirectory>
<moduleSets>
<moduleSet>
<includeSubModules>true</includeSubModules>
<useAllReactorProjects>true</useAllReactorProjects>
<includes>
<include>com.myCompany:mod1</include>
<include>com.myCompany:mod2</include>
<!-- and others... -->
</includes>
<binaries>
<includeDependencies>true</includeDependencies>
<outputDirectory>modules/maven-assembly-plugin</outputDirectory>
<unpack>false</unpack>
</binaries>
</moduleSet>
</moduleSets>
</assembly>
(I realize that at some point I will probably need to change <format>dir</format> to <format>jar</format> but for now, I'd just like to get something working)
When I run mvn clean package from the main parent module's directory, I get warnings like this:
[INFO] Reading assembly descriptor: src/assembly/assembly.xml
[WARNING] The following patterns were never triggered in this artifact inclusion filter:
o 'com.myCompany:mod1'
o 'com.myCompany:mod2'
...
Followed by the error:
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-assembly-plugin:3.1.0:single (distro-assembly) on project distribution: Failed to create assembly: Error creating assembly archive bin: archive cannot be empty -> [Help 1]
What I actually want:
One jar file containing all of my modules, and all of their dependencies (that is, the *-with-dependencies.jars), as a single jar file with everything contained inside.
I'm really not sure how to achieve this in a multi-module context.
I think I may have resolved it: the child modules mod1, mod2, ... were missing the parent module dependency. I've added
<parent>
<groupId>com.mycompany</groupId>
<artifactId>BigProject</artifactId>
<version>0.0.1</version>
</parent>
to the relevant child modules and now the build doesn't fail, but populates the target directory under the distribution project.
I have a multi-module project and one of the modules should create an EAR out of the other modules artifacts. To make things more interesting, these other 4 artifacts have to be shaded into 2 artifacts:
super-pom
|-- ear module
|-- ejb1
|-- ejb2
|-- web1
|-- web2
What it creates is an EAR containing ejb2-shaded, web2-shaded AND ej1, web1 (which are included in the shaded versions!).
Oddly enough, if I run maven manually in each module and in the ear-module in the end, I get what I wanted.
What I can't figure out is, how the super-pom sneaks these artifacts into the EAR. Event maven package -X only lists the right artifacts in the ear cration step:
[DEBUG] Resolving artifact type mappings ...
[DEBUG] Initializing JBoss configuration if necessary ...
[DEBUG] Initializing ear execution context
[DEBUG] Resolving ear modules ...
[DEBUG] Resolving ear module[ejb:com.mycomp:ejb2]
[DEBUG] Resolving ear module[war:com.mycomp:web2]
[DEBUG] Resolving ear module[jar:org.jboss.seam:jboss-seam]
[INFO] Generating application.xml
Some simplified poms, starting with the super-pom:
<artifactId>super-pom</artifactId>
<packaging>pom</packaging>
<modules>
<module>ejb1</module>
<module>web1</module>
<module>ejb2</module>
<module>web2</module>
<module>ear</module>
</modules>
ear-pom:
<artifactId>ear</artifactId>
<packaging>ear</packaging>
<parent>
...
<artifactId>super-pom</artifactId>
...
</parent>
<dependencies>
<dependency>
...
<artifactId>ejb2</artifactId>
<type>ejb</type>
...
</dependency>
<dependency>
...
<artifactId>web2</artifactId>
<type>ejb</type>
...
</dependency>
<!-- Little "trick" to avoid listing all shared deps from WAR. To use skinyWar,
deps to be shared via EAR/lib must be explicitly listed here. Including the
POM let's maven deal with this -->
<dependency>
...
<artifactId>web2</artifactId>
<type>pom</type>
...
</dependency>
</dependencies>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-ear-plugin</artifactId>
<version>2.6</version>
<configuration>
<!-- Tell Maven we are using Java EE 6 -->
<version>6</version>
<defaultLibBundleDir>lib</defaultLibBundleDir>
<!-- See maven docs; Necessary because we CAN'T have 2 jboss-seam.jars
in the same EAR -->
<skinnyWars>true</skinnyWars>
<initializeInOrder>true</initializeInOrder>
<modules>
<ejbModule>
<groupId>com.mycomp</groupId>
<artifactId>ejb2</artifactId>
</ejbModule>
<webModule>
<groupId>com.mycomp</groupId>
<artifactId>web2</artifactId>
<contextRoot>/</contextRoot>
</webModule>
<jarModule>
<groupId>org.jboss.seam</groupId>
<artifactId>jboss-seam</artifactId>
<includeInApplicationXml>true</includeInApplicationXml>
<bundleDir>/</bundleDir>
</jarModule>
</modules>
</configuration>
</plugin>
</plugins>
ejb2-pom:
<artifactId>ejb2</artifactId>
<packaging>ejb</packaging>
<parent>
...
<artifactId>super-pom</artifactId>
...
</parent>
<dependencies>
<dependency>
...
<artifactId>ejb1</artifactId>
<type>ejb</type>
...
</dependency>
</dependencies>
<plugins>
...
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>2.4.2</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<promoteTransitiveDependencies>true</promoteTransitiveDependencies>
<artifactSet>
<includes>
<include>com.mycomp:ejb1</include>
</includes>
</artifactSet>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
web2-pom:
<artifactId>web2</artifactId>
<packaging>war</packaging>
<parent>
...
<artifactId>super-pom</artifactId>
...
</parent>
<dependencies>
<dependency>
...
<artifactId>web1</artifactId>
<type>war</type>
...
</dependency>
</dependencies>
<plugins>
...
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>2.4.2</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<promoteTransitiveDependencies>true</promoteTransitiveDependencies>
<artifactSet>
<includes>
<include>com.mycomp:web1</include>
</includes>
</artifactSet>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
It is a multi-module maven project. I have included flatten-maven-plugin in my parent pom
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>flatten-maven-plugin</artifactId>
<version>1.0.0-beta-2</version>
<configuration>
</configuration>
defined a property scl_version in parent pom and used ${scl_version} in of child pom. Value is 0.0.1 .
when i run mvn flatten:flatten
It generates a warning :
[WARNING] 'version' contains an expression but should be a constant.
A flattened pom is created in all modules including parent and all the childs.
Flattened pom has value of the property in version tag of child pom. But when i give, mvn install it still gives warning that version should be constant but it is an expression.
http://mojo.codehaus.org/flatten-maven-plugin/plugin-info.html
But documentation says:
This MOJO realizes the goal flatten that generates the flattened POM
and potentially updates the POM file so that the current
MavenProject's file points to the flattened POM instead of the
original pom.xml file. The flattened POM is a reduced version of the
original POM with the focus to contain only the important information
for consuming it. Therefore information that is only required for
maintenance by developers and to build the project artifact(s) are
stripped.
so when i do mvn install it should not generate warning.
mvn install and mvn flatten:flatten both generates this warning:
[WARNING] 'version' contains an expression but should be a constant.
Am i missing something, is it not using flattened-pom.xml.
Do i need to specify something.
PARENT 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>
<groupId>org.a.b</groupId>
<artifactId>ABC</artifactId>
<version>0.0.1</version>
<packaging>pom</packaging>
<name>ABC</name>
<modules>
<module>Resources</module>
<module>ResourceTree</module>
<module>Service</module>
<module>Transport</module>
<module>Branding</module>
properties tag starts here
<scl_version>0.0.1</scl_version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven-compiler-plugin.version>3.1</maven-compiler-plugin.version>
<karaf.deploy.build.folder>${env.KARAF_BASE}/deploy</karaf.deploy.build.folder>
property tag ends here
<profiles>
<profile>
<id>code_coverage</id>
<build>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>${maven-compiler-plugin.version}</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.7.0.201403182114</version>
<executions>
<execution>
<id>default-instrument</id>
<goals>
<goal>instrument</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.12.2</version>
<configuration>
<systemPropertyVariables>
<jacoco-agent.destfile>target/jacoco.exec</jacoco-agent.destfile>
</systemPropertyVariables>
</configuration>
</plugin>
</plugins>
</build>
</profile>
</profiles>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>flatten-maven-plugin</artifactId>
<version>1.0.0-beta-2</version>
<configuration>
<flattenMode>ossrh</flattenMode>
<updatePomFile>true</updatePomFile>
</configuration>
<executions>
<!-- enable flattening -->
<execution>
<id>flatten</id>
<phase>process-resources</phase>
<goals>
<goal>flatten</goal>
</goals>
</execution>
<!-- ensure proper cleanup -->
<execution>
<id>flatten.clean</id>
<phase>clean</phase>
<goals>
<goal>clean</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>${maven-compiler-plugin.version}</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
</dependency>
<dependency>
<groupId>org.jacoco</groupId>
<artifactId>org.jacoco.agent</artifactId>
<classifier>runtime</classifier>
<version>0.7.0.201403182114</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>
generated flattened pom:
<?xml version="1.0" encoding="UTF-8"?>
<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>
<groupId>org.a.b</groupId>
<artifactId>ABC</artifactId>
<version>0.0.1</version>
<packaging>pom</packaging>
<name>ABC</name>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
<scope>compile</scope>
</dependency>
</dependencies>
<repositories>
<repository>
<snapshots>
<enabled>false</enabled>
</snapshots>
<id>central</id>
<name>Maven Repository Switchboard</name>
<url>http://repo1.maven.org/maven2</url>
</repository>
</repositories>
</project>
property is used in grand grand child pom ( for trail, if successfull without warning, i can iuse it everywhere):
<groupId>org.a.b</groupId>
<artifactId>CD<artifactId>
<version>${scl_version}</version>
<packaging>bundle</packaging>
<name>CD</name>
<description>OSGi bundle project.</description>
Apart from this, it has bundle plugin dependency plugin and some dependencies. In flattened pom ofthis child this version is resolved to 0.0.1
I mailed to developer of this plugin and his response is:
The warning is coming from Maven, based on the original pom.xml
Before Maven starts executing, a buildplan is created and the pom.xml
is analyzed, causing this warning. The flatten-maven plugin kicks in
later in the process generating the flattened pom.xml and making sure
that's the file being installed/deployed. Your issue can't be fixed by
the flatten-maven-plugin and won't be fixed in Maven Core (the warning
is there for a good reason).
So, it answers the question very well.
I have a project consisting of 3 libraries - let's call them 1) BABY, 2) CHILD and 3) ADULT. Lib "CHILD" depends on "BABY" and "ADULT" depends on "CHILD".
What I want to do is produce:
a dev version that has all the (transitive) dependencies
a production version that creates a standalone JAR for each library (embedding the dependencies)
I have a profile dev and a profile release already, and I know how to use ProGuard to generate the JAR.
The question is how to tell Maven to keep all dependencies in dev and ignore them (optional/provided) in production?
To have different dependencies when you develop to deployment you could use maven profiles.
http://maven.apache.org/guides/introduction/introduction-to-profiles.html
So when developing you would use something like mvn -Pdev compile
When you say "standalone jar" it sounds like you mean a jar with all dependencies merged into it.
How can I create an executable JAR with dependencies using Maven?
or http://maven.apache.org/plugins/maven-assembly-plugin/
Here is what I used eventually:
The parent POM defines a profile release that configurates the proguard plugin (crates one big JAR) and the install plugin (places the release artifact in the repo).
The lib-baby POM simply calls the 2 plugins in the <build> section.
The lib-child POM additionally specifies a dev profile where the dependency to lib-baby is defined. Within the release profile this dependency has an optional tag and is included in the big JAR.
In the end when run by default, the libs com.company.dev:lib-baby and com.company.dev:lib-child are created (included their dependencies).
When run with -Prelease the libs com.company:lib-baby and com.company:lib-child are created (standalone libs [WITHOUT any dependencies]) - only side effect is that the default artifacts (.*dev) are overwritten :(
parent:
<project>
<groupId>com.company</groupId>
<artifactId>lib-parent</artifactId>
<packaging>pom</packaging>
<modules>
<module>lib-baby</module>
<module>lib-child</module>
<module>lib-adult</module>
</modules>
<profiles>
<profile>
<id>release</id>
<activation>
<property>
<name>release</name>
</property>
</activation>
<build>
<pluginManagement>
<plugins>
<!-- aggregate to one big jar -->
<plugin>
<groupId>com.pyx4me</groupId>
<artifactId>proguard-maven-plugin</artifactId>
<executions>
...
</executions>
<configuration>
<injar>${project.build.finalName}.jar</injar>
<outjar>${project.build.finalName}-release.jar</outjar>
....
</configuration>
</plugin>
<!-- install release version of artifact separately (under com.company) -->
<plugin>
<inherited>true</inherited>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-install-plugin</artifactId>
<executions>
<execution>
<id>install-release</id>
<goals>
<goal>install-file</goal>
</goals>
<configuration>
<file>
target/${project.build.finalName}-release.jar
</file>
<groupId>com.company</groupId>
...
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</pluginManagement>
</build>
</profile>
</profiles>
</project>
lib-baby:
<project>
<groupId>com.company.dev</groupId>
<artifactId>lib-baby</artifactId>
<packaging>jar</packaging>
<parent>
<groupId>com.company</groupId>
<artifactId>lib-parent</artifactId>
</parent>
<profiles>
<profile>
<id>release</id>
<build>
<plugins>
<!-- produces 'lib-baby-release.jar -->
<plugin>
<groupId>com.pyx4me</groupId>
<artifactId>proguard-maven-plugin</artifactId>
</plugin>
<!-- installs 'lib-baby-release.jar -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-install-plugin</artifactId>
<executions>
<execution>
<id>install-release</id>
<phase>install</phase>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
</profiles>
</project>
lib-child:
<project>
<groupId>com.company.dev</groupId>
<artifactId>lib-child</artifactId>
<packaging>jar</packaging>
<parent>
<groupId>com.company</groupId>
<artifactId>lib-parent</artifactId>
</parent>
<profiles>
<profile>
<id>dev</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<dependencies>
<dependency>
<groupId>com.company.dev</groupId>
<artifactId>lib-baby</artifactId>
</dependency>
</dependencies>
</profile>
<profile>
<id>release</id>
<dependencies>
<dependency>
<groupId>com.company.dev</groupId>
<artifactId>lib-baby</artifactId>
<version>1.0</version>
<!-- made optional because will be embedded in standalone jar -->
<optional>true</optional>
</dependency>
</dependencies>
<build>
<plugins>
<!-- produces 'lib-child-release.jar -->
<plugin>
<groupId>com.pyx4me</groupId>
<artifactId>proguard-maven-plugin</artifactId>
<configuration>
<assembly>
<inclusions>
<inclusion>
<groupId>com.company.dev</groupId>
<artifactId>lib-baby</artifactId>
</inclusion>
</inclusions>
</assembly>
</configuration>
</plugin>
<!-- installs 'lib-child-release.jar -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-install-plugin</artifactId>
<executions>
<execution>
<id>install-release</id>
<phase>install</phase>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
</profiles>
</project>