How to generate child project build in parent project directory - maven

I'm looking for the simple way to generate the child project artifact in the parent project directory using maven.
I have tried directory-maven-plugin and assigned a variable to the parent project. And I've provided this variable in the child pom. Now the child is trying to create a folder with Parent name in it instead of copying the dependencies to parent project folder
Parent.pom
<modelVersion>4.0.0</modelVersion>
<groupId>com.parent.project</groupId>
<artifactId>parent</artifactId>
<version>1.0</version>
<packaging>pom</packaging>
<build>
<plugins>
<plugin>
<groupId>org.commonjava.maven.plugins</groupId>
<artifactId>directory-maven-plugin</artifactId>
<version>0.1</version>
<executions>
<execution>
<id>directories</id>
<goals>
<goal>highest-basedir</goal>
</goals>
<phase>initialize</phase>
<configuration>
<property>main.basedir</property>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
<modules>
<module>child</module>
</modules>
child.pom
<groupId>com.wellsfargo.1coh</groupId>
<artifactId>child</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>war</packaging>
<parent>
<groupId>com.parent.project</groupId>
<artifactId>parent</artifactId>
<version>1.0</version>
</parent>
<build>
<directory>${main.basedir}/target/</directory>
</build>
Child jar file is getting generated inside child folder instead of parent folder like below-
child/c:/foldername/workspace/parent/target/child.jar
What I'm looking for should be like this-
parent/target/child.jar

create several modules in parent pom as below
<modules>
<module>ChildProjectB</module>
<module>ChildProjectC</module>
<module>ChildProjectD</module>
</modules>
refer the link
http://websystique.com/maven/creating-maven-multi-module-project-with-eclipse/

Related

Maven SCM plugin and relative paths

My directory structure looks somewhat like this:
.git
src
parent
pom.xml
submodule
pom.xml
addme.product
My pom 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">
<scm>
<developerConnection>scm:git:file://../../.git</developerConnection>
</scm>
<modelVersion>4.0.0</modelVersion>
<groupId>grp</groupId>
<artifactId>artif</artifactId>
<version>1.0.0</version>
<packaging>pom</packaging>
<modules>
<module>../submodule</module>
</modules>
</properties>
<build>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-release-plugin</artifactId>
<version>2.5.3</version>
<configuration>
<autoVersionSubmodules>true</autoVersionSubmodules>
<localCheckout>true</localCheckout>
<preparationGoals>
org.eclipse.tycho:tycho-versions-plugin:${tycho-version}:update-eclipse-metadata
org.apache.maven.plugins:maven-scm-plugin:1.9.5:add
<!-- org.apache.maven.plugins:maven-scm-plugin:1.9.5:checkin -->
</preparationGoals>
<completionGoals>
org.eclipse.tycho:tycho-versions-plugin:${tycho-version}:update-eclipse-metadata
org.apache.maven.plugins:maven-scm-plugin:1.9.5:add
<!-- org.apache.maven.plugins:maven-scm-plugin:1.9.5:checkin -->
</completionGoals>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-scm-plugin</artifactId>
<version>1.9.5</version>
<executions>
<execution>
<id>default-cli</id>
<goals>
<goal>add</goal>
<goal>checkin</goal>
</goals>
<configuration>
<includes>**/META-INF/MANIFEST.MF,**/feature.xml,**/*.product</includes>
<excludes>**/target/**</excludes>
<message>Changing the version to reflect the pom versions for the release</message>
<basedir>${project.basedir}/../..</basedir>
<workingDirectory>${project.basedir}/../..</workingDirectory>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</project>
When I run mvn release:prepare, I get an error saying that
[ERROR] fatal: pathspec 'src\parent\src\submodule\addme.product' did
not match any files
So, the plugin finds the files it should add, but when creating the command line doesn't respect the correct root directory. How do I fix this, without changing the location of the parent pom?
I ran into a similar problem (my root POM had a parent configuration POM, which was located in a subfolder). I was only able to solve this by creating a "proper" POM and folder hierarchy, meaning:
Root POM should be located in the project root folder
Submodlues should be subfolders of the project root folder and the folder structure should be reflected in the of the POMs
Source folders should be individual subfolders of the modules

Get war module when running the parent maven project

Is there a way to run a war module automatically when I run the parent project?
To make it clear, I did three separate maven project (db, core and presentation), then I made a parent project which include the 3 projects mentioned before.
I'd like to get the presentation module running when I run the parent project.
Also, I want to know if it's possible to save the hole work from the parent project to my git account.
<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.project.xxxxxxx</groupId>
<artifactId>parent-project</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>pom</packaging>
<name>parent-project</name>
<url>http://maven.apache.org</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<targetJdk>1.7</targetJdk>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.apache.tomcat.maven</groupId>
<artifactId>tomcat7-maven-plugin</artifactId>
<version>2.0</version>
<configuration>
<port>8080</port>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>${targetJdk}</source>
<target>${targetJdk}</target>
<showDeprecation>true</showDeprecation>
</configuration>
</plugin>
</plugins>
</build>
<modules>
<module>../project-db</module>
<module>../project-core</module>
<module>../project-presentation</module>
</modules>
<dependencies>
</dependencies>
</project>
You need to specify the sub-project under tag.
You may refer http://books.sonatype.com/mvnex-book/reference/multimodule-sect-simple-parent.html for example
Your modules should be unter your parent in the file structure. Like
parent-project
pom.xml
project-db
pom.xml
project-core
pom.xml
project-presentation
pom.xml
Then you have to change the parent pom:
<modules>
<module>project-db</module>
<module>project-core</module>
<module>project-presentation</module>
</modules>

Maven assembly plugin - dependendy on module of type ear in multi module project

My question is whether there is anyway with the maven assembly plugin to reference a dependency of type ear that is not installed in the artefactory/repository.
Consider the multi-module project below with parent:
<?xml version="1.0" encoding="UTF-8"?>
<project ...>
<modelVersion>4.0.0</modelVersion>
<groupId>com.test</groupId>
<artifactId>parent</artifactId>
<version>1.0</version>
<packaging>pom</packaging>
<name>parent</name>
<modules>
<module>module1</module>
<module>assembly</module>
</modules>
</project>
with ear module:
<?xml version="1.0"?>
<project ...>
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.test</groupId>
<artifactId>parent</artifactId>
<version>1.0</version>
</parent>
<groupId>com.test</groupId>
<artifactId>module1</artifactId>
<packaging>ear</packaging>
<name>EAR Module</name>
</project>
and assembly module:
<?xml version="1.0"?>
<project ...>
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.test</groupId>
<artifactId>parent</artifactId>
<version>1.0</version>
</parent>
<groupId>com.test</groupId>
<artifactId>assembly</artifactId>
<packaging>jar</packaging>
<name>Assembly Module</name>
<dependencies>
<!-- Note - the dependencies (and their associated dependencies etc) are
subsequently available for assembly dependencySet includes -->
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>module1</artifactId>
<type>ear</type>
<version>${project.version}</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<appendAssemblyId>false</appendAssemblyId>
<descriptors>
<descriptor>assembly.xml</descriptor>
</descriptors>
</configuration>
<executions>
<execution>
<id>make-assembly</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
with an assembly xml :
<assembly xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2 http://maven.apache.org/xsd/assembly-1.1.2.xsd">
<id>bundle</id>
<formats>
<format>zip</format>
</formats>
<includeBaseDirectory>false</includeBaseDirectory>
<dependencySets>
<!--
Include EAR
-->
<dependencySet>
<useProjectArtifact>false</useProjectArtifact>
<outputFileNameMapping>xxxxxxxxx.ear</outputFileNameMapping>
<outputDirectory>eardirectory</outputDirectory>
<includes>
<include>${pom.groupId}:module1:ear</include>
</includes>
</dependencySet>
</dependencySets>
</assembly>
From a brand new checkout with empty repository, the parent project pom fails when doing a mvn compile with the error
[ERROR] Failed to execute goal on project assembly: Could not resolve dependencies for project com.test:assembly:jar:1.0: Could not find artifact com.test:module1:ear:1.0 ...
Whereas, if I first go to the ear module and do a mvn install, then subsequent mvn compile from the parent module works perfectly.
Additionally, if the ear module was instead the standard jar module, then this issue does not exist. Such that, if the dependency module had been of type jar, there is no need to first install it in to the local repos before doing the initial mvn compile from the parent.
Switching the dependency in the assembly pom to be of scope 'runtime' allows an initial mvn compile to succeed, however a mvn test would fail. Setting the dependency as optional also did not succeed.
Can anyone suggest a potential solution?
I'm hoping I don't need to go down the fileSet path, or utilize the maven-dependency-plugin. This dependency only exists in the pom so that the assembly plugin can package it / reference it. It is not for compilation / runtime / testing. So none of the maven dependency scopes make any sense.

copy jars used by plugin to single folder using Maven

In my POM.xml other the plugin configuration, i am not required to configure any dependenices to run the plugin. I would like to download dependent jars used by plugin(soapui-maven-plugin) from the repository into one single folder. I tried the command "mvn dependency:copy-dependencies", but no jars are copied. Is there any way to do it?
<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>service.report</groupId>
<artifactId>service-report</artifactId>
<packaging>jar</packaging>
<version>1.0-SNAPSHOT</version>
<name>Maven 2 SoapUI Sample</name>
<build>
<plugins>
<plugin>
<groupId>com.smartbear.soapui</groupId>
<artifactId>soapui-maven-plugin</artifactId>
<version>5.0.0</version>
<executions>
<execution>
<phase>test</phase>
<goals>
<goal>loadtest</goal>
</goals>
<configuration>
<projectFile>${basedir}/src/main/resources/xxxxx-soapui-project.xml</projectFile>
<testSuite>xxxx</testSuite>
<testCase>sssss</testCase>
<loadTest>LoadTest 1</loadTest>
<outputFolder>${basedir}/target/surefire</outputFolder>
<junitReport>true</junitReport>
<exportAll>true</exportAll>
<printReport>true</printReport>
<testFailIgnore>false</testFailIgnore>
<!-- <projectProperties>
<value>message=Hello World!</value>
</projectProperties> -->
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
mvn dependency:copy-dependencies is only applied to current maven module only. It won't works on plugins. If you want to download all soapui-maven-plugin dependencies, you need to execute command from soapui-maven-plugin project. You can follow the following steps. I assumed you familiar with GIT CLI. If not, you need to manually download from https://github.com/SmartBear/soapui
git clone https://github.com/SmartBear/soapui
cd soapui/soapui-maven-plugin
mvn dependency:copy-dependencies
You can get list of dependencies in soapui/soapui-maven-plugin/target/dependency (total 82files)
[ERROR] Failed to execute goal on project soapui-maven-plugin: Could not resolve dependencies for project com.smartbear.soapui:soapui-maven-plugin:maven-plugin:5.0.0: Could not find artifact javafx:jfxrt:jar:2.2 at specified path (your jdk path)
If you get the above error, it means your maven jdk is version jdk.1.7 (u6 or earlier) which is not installed with javafx. Download newer jdk that comes with javafx at http://www.oracle.com/technetwork/java/javase/downloads/jdk7-downloads-1880260.html . Remember change your maven jdk to this newer jdk.
If you want to use the dependency-plugin you could add the dependencies to the pom...and download with the depepndency-plugin...
It works right for me...
<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.ab.forge.utility.copydependenciespom</groupId>
<artifactId>copydependenciespom</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>pom</packaging>
<!-- BINARIES -->
<dependencies>
<!--CUSTOMER RETURN -->
<dependency>
<groupId>com.ab...</groupId>
<artifactId>customerret.....</artifactId>
<version>1.0-SNAPSHOT</version>
<scope>compile</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<phase>install</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<overWriteIfNewer>true</overWriteIfNewer>
<overWriteReleases>true</overWriteReleases>
<overWriteSnapshots>true</overWriteSnapshots>
<excludeGroupIds>com.ab.ah.scad.acl</excludeGroupIds>
<excludeTypes>pom</excludeTypes>
<includeGroupIds>com.ab.oneleo</includeGroupIds>
<outputDirectory>${outputDirectory}</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
After I just run the install passing the -DoutputDirectory parameter....
Try this...
To view all the plugin dependencies you can run a dependency:tree on the pom (where the plugin in configured)

Dependency management does not work for multi-module project

I have a Maven project with multiple modules and I'm trying to set it up so that module dependencies are automatically built to the correct lifecycle phase needed for building depending modules to the requested lifecycle phase.
In the example, the module plugin builds a Maven plugin, which is used to generate source code and is used by the module main. If I just try to use mvn -am -pl main compile, the module plugin is compiled but the process-classes lifecycle phase is not executed (which is necessary for a plugin to be usable). Compiling the module main then fails then with the following error:
[ERROR] Failed to parse plugin descriptor for example:plugin:1.0.0-SNAPSHOT (/Users/ims/Dropbox/IMS/Projects/PARITy_R4/codegen-test-simple/plugin/target/classes): No plugin descriptor found at META-INF/maven/plugin.xml -> [Help 1]
Is Maven, or a plugin for it, capable of resolving the dependencies of modules in a multi-module project and build them to stage necessary by other modules? And if so, how do I need to set up the project for this to work?
These are the POMs of my project:
pom.xml:
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<project xmlns="http://maven.apache.org/POM/4.0.0">
<modelVersion>4.0.0</modelVersion>
<groupId>example</groupId>
<artifactId>project</artifactId>
<version>1.0.0-SNAPSHOT</version>
<packaging>pom</packaging>
<modules>
<module>plugin</module>
<module>main</module>
</modules>
</project>
plugin/pom.xml:
<project xmlns="http://maven.apache.org/POM/4.0.0">
<modelVersion>4.0.0</modelVersion>
<groupId>example</groupId>
<artifactId>plugin</artifactId>
<version>1.0.0-SNAPSHOT</version>
<packaging>maven-plugin</packaging>
<parent>
<groupId>example</groupId>
<artifactId>project</artifactId>
<version>1.0.0-SNAPSHOT</version>
</parent>
<dependencies>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-plugin-api</artifactId>
<version>2.0</version>
</dependency>
<dependency>
<groupId>org.apache.maven.plugin-tools</groupId>
<artifactId>maven-plugin-annotations</artifactId>
<version>3.2</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-plugin-plugin</artifactId>
<version>3.2</version>
<configuration>
<goalPrefix>configurator</goalPrefix>
</configuration>
<executions>
<execution>
<id>default-descriptor</id>
<goals>
<goal>descriptor</goal>
</goals>
<phase>process-classes</phase>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
main/pom.xml:
<project xmlns="http://maven.apache.org/POM/4.0.0">
<modelVersion>4.0.0</modelVersion>
<groupId>example</groupId>
<artifactId>main</artifactId>
<version>1.0.0-SNAPSHOT</version>
<packaging>jar</packaging>
<parent>
<groupId>example</groupId>
<artifactId>project</artifactId>
<version>1.0.0-SNAPSHOT</version>
</parent>
<build>
<plugins>
<plugin>
<groupId>example</groupId>
<artifactId>plugin</artifactId>
<version>1.0.0-SNAPSHOT</version>
<executions>
<execution>
<goals>
<goal>codegen</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
If you look at the reference documentation for the Maven lifecycle, you'll see that compile is before process-classes.
If you want this step to happen, you need to use mvn -am -pl main process-classes instead.
But I suggest that you always use mvn ... install - it also runs the tests and makes sure that the plugin which main uses is actually the one you think it should: Without install, the build will use an old/outdated version from the local repository (Maven will not magically determine "oh, there is a plugin in my reactor, I'll use that instead of the version from the local repo").

Resources