The goal "copy-dependencies" does not copy the parent pom - maven-3

My project structure is like this:
* Foo
- API
- Core
- OSGi
All child projects define Foo as their parent (parent has dependencyManagement).
Another team is going to use my project. They only need my API layer and they cannot access my maven repository.
I need to give them all the dependencies of my API so I executed the following maven command:
mvn dependency:copy-dependencies -DincludeScope=compile -Dmdep.copyPom
-Dmdep.useRepositoryLayout
The dependency-plugin copies everything just fine except for the parent pom. How can I add the parent pom.xml to the output folder?

see the addParentPoms option here http://maven.apache.org/plugins/maven-dependency-plugin/copy-dependencies-mojo.html

Related

Copy maven plugin from dependency with type pom

I have project A which contains following dependency:
<dependency>
<groupId>vo.cjm.modules.shared</groupId>
<artifactId>basic</artifactId>
<version>1.0.0</version>
<type>pom</type>
</dependency>
In the pom of this dependency I have a plugin configured. However, this plugin is never executed when installing the project in the maven local repo. When moving the plugin to the pom of project A, it is executed.
In contrast to parent-child maven projects where plugins are inherited, here I find myself in the situation where only dependencies are inherited. Is it true that when using pom type, only dependencies are inherited and no plugins? If yes, how can I achieve to inherit plugins in maven without parent-child structure?
What I also tried, was using a parent project. In this project I define the child module, project A. In project A, I reference the parent project. When doing this, maven generates 'duplicate version' errors/warnings. The only way to eliminate this behavior is removing the version of project A. Now, projects A version is inherited from the parent project. I want to be able to manage the version of project A independently, so this is not an option.
I also tried to use a parent project, and define a module (project A) in there. However, this only works with the assumption you will always call maven on the parent project. Running maven on project A, will not inherit anything that is in the parent project.
You have to distinguish the parent-child mechanism and the dependency mechanism.
When specifying a parent for a pom (thus becoming a child pom), you will inherit every dependencies and plugins declared in <dependencies> and <plugins> elements, among other things
When referencing dependencies in your pom with <dependencies>, you're telling Maven "I need this artifact (jar, pom, other) in my project, and any other dependency this artifact is also depending on", but nothing related to plugins used by this dependency. Plugins are only used when building something with Maven. Once the artifact is built and available, there is no reason to include the plugins used by this artifact when it was built - imagine if for every dependency you used, you had tons of plugins you probably don't want suddenly added to your build !
Is it true that when using pom type, only dependencies are inherited and no plugins?
Yes. When your dependency is of type pom, you're simply telling Maven to add all the dependencies of this pom to the current pom.
If yes, how can I achieve to inherit plugins in maven without parent-child structure?
To the best of my knowledge, you can't. You have to use a parent pom if you want to inherit plugins.
I'd say that dependencies are not part of the Maven project object model, so I'd say no.
We're using parent-child architectures to reuse plugins from parents.
We omit using them as Snapshots
parent with plugins +
|
+ another parent with plugins +
| |
| + child artifact uses plugins
+ child artifact uses plugins
and so on.
So parents can for example define a Java version, or they can contain profiles that child projects can use.
These are no reactor projects (no "modules"), just plain POM projects for this exact reason: To provide plugins, profiles and dependencyManagement for children.

How to nest multi-module maven projects in jenkins?

My project structure looks like this:
services
A
a1
a2
pom.xml
B
b1
b2
pom.xml
pom.xml
I would like to scan the inner-most projects (a1,a2,b1,b2). In jenkins Post Steps, I added "Analysis properties" in Execute SonarQube Scanner without property files, mainly:
sonar.modules=A,B
sonar.sources=src
I would like to build from services directory, but it failed with this ERROR:
The folder 'src' does not exist for 'A:a1'
I understand, that SonarQube tries to find src inside the directory A, but I have a few nested projects like a1 (I also tried A.modules=a1,a2 without success)
How can I make the scanner analyze these projects?
this is my solution:
sonar.modules=A,B
A.sonar.modules=a1,a2
B.sonar.modules=b1,b2
sonar.projectBaseDir=.
sonar.sources=src
the key point is projectBaseDir ,I hope this can help someone meet the similar problem.
Use the maven goal sonar:sonar instead of a sonar.properties configuration, when analyzing maven projects with SonarQube.
You should not even have to change any analysis property, when using maven. The maven configuration will already give sonar information about source folders, etc. Check the official documentation on how to set it up. Usually you do not have to change the pom.xml of the projects for this (only you local maven settings.xml).

Parent POM with Multiple - Multiple Modules having dependency

We had a relative flat project structure in CVS and post migration to Git we encountered a issue due to how Git repository were checkout. A CVS repository was never checkout, but with Git on Eclipse we see a repository folder under which projects are checkout. This has caused issue with our Maven script.
The new structure is:
I added the pom.xml file under idml and leancore that refer to parent pom.xml. the project below idml refers the intermediate idml parent pom.xml and leancore refer intermediate leancore parent pom.xml.
How do I define the dependency between 2 Multiple Modules project?
What will go into the parent POM to support this kind of structure?
How can AdjHubCore refer to a dependency in idml - idmlj2eert?
We would like to build all the module and war file from the root parent pom.xml file.
Your idmlj2eert POM looks like:
...
<groupId>idml</groupId>
<artifactId>idmlj2eert<artifactId>
<version>0.0.1-SNAPSHOT<>version>
...
Then your AdjHubCore looks like:
...
<dependency>
<groupId>idml</groupId>
<artifactId>idmlj2eert<artifactId>
<version>0.0.1-SNAPSHOT<>version>
</dependency>
...
An alternative is to use <dependencyManagement> in your root POM, such avoiding having to declare a dependency's version in child POMs. Your root POM has to be a <parent> POM, direct or transitive across multiple levels, of such a child POM then.
So, that's not different to any other dependency. The Maven Reactor takes care of the proper build order according to (intra-)dependencies inside a multi-module project at the beginning of the build.
Remember, aggregation (multi-module) and inheritance (parent/child relationships) are different things. A project can use either of them and it can use both, too. See POM Reference, Inheritance v. Aggregation and Maven: The Complete Reference, 3.6.2. Multi-module vs. Inheritance.

Build a project from sub-directory of Bitbucket repository in Jenkins

Is it possible to build a project inside sub-directory of Bitbucket repository in Jenkins? I have been trying and testing Jenkins build from sub-directory of Bitbucket respository instead building everything from master branch because I do not want to put load on servers just for the testing purpose. I would like to know if it is possible and how it can be done. For instance, I would like to build only a project from sub directory 2 of Bitbucket repository as shown below. Please help with the diagram if possible. Thanks.
*/master
- Directory 1
- sub directory 1
- pom.xml
- **sub directory 2
- pom.xml**
- Directory 2
- sub directory A
- subdirectory B
- pom.xml
If anyone is still looking for an answer, you need to provide the path of pom.xml in the Root POM of Build section of Configure.
Go to Configure -> Scroll down to Build -> in Root POM enter subdirectory name/pom.xml
[image reference]1
e.g. If your pom.xml is present at Repo/subdirectory/pom.xml you need to enter subdirectory/pom.xml in Root POM

Maven inheritance does not work when invoking plugin goals from command line

I have a multi module project. There is a parent pom in which I have added the maven-dependency plugin to the plugin management section. I have not tied this plugin's execution to a phase. In one of the child modules pom.xml, I have added this same plugin with different configuration.
However when I execute from the command line
mvn dependency:copy
Then only my parent pom plugin configuration executes for the maven-dependency plugin and all the child modules are skipped. Why is this? Does inheritance work only if plugins are tied to a specific phase?
The simple answer to this is: If you try to run maven via command like you did you are calling a plugin but you will not run the life cyclce which is needed to get the inheritance mechanism take care of the pom files. In your examples if you would start the life cylce with something like:
mvn package
or something similar like:
mvn verify
all your sub modules would be visited during the life cyclce.

Resources