Maven says it cannot find something in the "reactor" - maven

I have a maven project and I'm using this --projects command from the root of the project to run several pom files.
mvn clean install --projects proj1, then-proj2
The proj1 and then proj2 are the artifact ids of the projects I want to run. That is, I go to the pom.xml for each project and use the "artifact id" there.
Both proj1 & then-proj2 are themeslves sub modules of projects in the main pom file.
Say proj1 is in A, and then-proj2 is in B, and both A & B are in the main pom file.
When I run this, maven tells me: "could not find the selected project in the reactor: proj1".
This is really frustrating - why not tell me what all the projects in the reactor are? Anyway, what am I doing wrong?

If you only use the artifactId's of the given project you have to define that correctly on command line:
help output of Maven (mvn --help)
Comma-delimited list of specified reactor projects to build of all
projects. A project can be specified by [groupId]:artifactId or by its
relative path
This means in your case you have to define:
mvn clean install --projects :proj1,:then-proj2

Try this:
mvn clean install -pl A/proj1, B/then-proj2
check this out: https://stackoverflow.com/a/23076358/1680793
Another thing is to make sure that you have listed your child projects inside the
<modules>
<module>
sections of the corresponding parent multimodule projects.
For example in the below project structure:
main
A
proj1
proj1A
B
then-proj2
Let's say you are trying to build proj1A. When you try
mvn package -pl A/proj1/proj1A
from the main's pom directory you will still have this same reactor error if you don't have:
"A" as a module in "main", or
"proj1" as a module in "A", or
"proj1A" as a module in "proj1"

If your modules are distinguished based on profiles then make sure to consider profiles too. Eg:
mvn -P profile1 -pl relative/path/to/project1 clean install
For this kind of setting, the pom would be:
<profiles>
<profile>
<id>profile1</id>
<modules>
<module>project1</module>
</modules>
</profile>
<profile>
<id>profile2</id>
<modules>
<module>project2</module>
</modules>
</profile>
</profiles>
Not mentioning profile would also give the Not Found in reactor.

A solution that worked for me, run the below command from the root directory.
mvn clean install --projects :projA, :projB -am
assuming that projB is dependent on projA
-am
If project list is specified, also
build projects required by the
list

The command used by you :
mvn clean install --projects 'submodule1','submodule2`
works on the sub-modules submodule1 and submodule2 specified in the pom.xml of the module where you're executing this command.
The guide to Working with Multiple modules shall help you understand the reactor and its sorting order. A general structure of the module for such use case would look like:
<groupId>stackoverflow</groupId>
<artifactId>mainmodule</artifactId>
<packaging>pom</packaging>
<version>1.2.3</version>
<modules>
<module>submodule1</module>
<module>submodule2</module>
... others
</modules>
... other tags

Related

How will you configure your pom.xml, so that another application bundle will not build again every time you run maven on your application?

In your application, you have to use another application bundle how will you configure your pom.xml, so that another application bundle will not build again every time you run maven on your application?
I assume you have a second maven dependency that gets build everytime you build your application. You ll need to modularize your parent POM and use separate profiles for partial build and full builds.
For example on your parent pom, modules section, include only your application core like this:
<modules>
<module>core</module>
</modules>
Under profiles, have separate profiles for application build and full build
<profiles>
<profile>
<id>autoInstallPackage</id>
<modules>
<module>ui.apps</module>
<module>ui.content</module>
</modules>....
<profile>
<profile>
<id>autoInstallWithSecondApplication</id>
<modules>
<module>secondapplication</module>
<module>ui.apps</module>
<module>ui.content</module>
</modules>....
<profile>
When you run mvn clean install -PautoInstallPackage, it will build core, ui.apps, ui.content. When you run mvn clean install -PautoInstallWithSecondApplication, it will build core and the dependency project, and then bundles up the deployment package.
You can easily exclude a sub-module as well, by using -pl '!moduleToExclude', this way, for example if you already have the code installed on AEM, you do not need to build it every time.

Maven Build specific childs from Parent

Can we build specific child from a parent Pom in Maven.May be using a file that mentions the name of the modules to be included.
If you in root location of your project you can simply define that on command line of Maven like this:
mvn -pl ModuleYouWouldLikeToBuild package
Excerpt from the command line help:
-pl,--projects <arg> Comma-delimited list of specified
reactor projects to build instead
of all projects. A project can be
specified by [groupId]:artifactId
or by its relative path.
If this module what you like to build is used by an other module you can decide to let maven analyze which one and build that depending module also by using:
mvn -pl Module --also-make-dependents
or short version:
mvn -pl Module -amd
If you have modules which are used by the module you triggered to build you can also add:
mvn -pl Module --also-make
or short version:
mvn -pl Module -am
Assume your root project has 3 modules: module-A, module-B and module-C.
Run the commands below from your root project.
If you want to build module-C, run: mvn clean install –pl module-C
In case module-C depends on module-A, run:
mvn clean install –pl module-C –am to build module-A and module-C
You can use maven profile to achieve this.
<project>
...
<profiles>
<profile>
<id>build1</id>
<activation>
<property>build1</property>
</activation>
<modules>
<module>module1</module>
</modules>
</profile>
<profile>
<id>build2</id>
<activation>
<file>
<exists>test2.file</exists>
</file>
</activation>
<modules>
<module>module2</module>
<module>module3</module>
</modules>
</profile>
</profiles>
</project>
You can activate profile by some conditions, eg. present or missing files, existing properties and so on.
More info about maven profile:
http://maven.apache.org/guides/introduction/introduction-to-profiles.html

How to exclude a single module from Javadoc generation in a Maven multi module project?

I have a Maven multi module project like this:
foo-parent
foo-module
foo-module-new
foo-other-module1
foo-other-module2
pom.xml
And when calling mvn javadoc:aggregate in foo-parent, I want to exclude the module foo-module from Javadoc generation.
Exclusion by package name with the parameter excludePackageNames doesn't work in my case because foo-module and foo-module-new have the same package name.
Launch the following to generate javadocs only for foo-other-module1 and foo-other-module2 modules (note: always include the aggregator module, in this case foo-parent):
mvn javadoc:aggregate -pl :foo-parent,:foo-other-module1,:foo-other-module2
Since Maven 3.2.1, you can also exclude modules from your reactor, so the above simplifies to
mvn javadoc:aggregate -pl '!foo-module'
Use maven profile.
add in your pom :
<profiles>
<profile>
<id>javadoc</id>
<modules>
<module>module_include_javadoc1</module>
<module>module_include_javadoc2</module>
</modules>
</profile>
</profiles>
Run this:
mvn javadoc:aggregate -Pjavadoc

How to maven build child projects?

I have aggregation where I link a parent Pom using the <modules> element, and then I have the <parent> specified in each child pom.
Is there a way I can build only a subset of the child modules from the parent pom... i.e.
cd parent-dir
mvn install subproj1 subproj2
You can run Maven like this: mvn install -pl subproj1,subproj2
PS: another good Maven command to try: mvn -?

hudson incremental maven build always fail, while full maven build succeeds

Upon each change commited to our svn, hudson initiates a maven build with the -amd -pl flags, to make only the changed projects. However, the project it compiles "a" is dependent on another project "b", and it fails while looking for "b" in maven repositories across the web. Half an hour later it does a full build and succeeds...
Maybe we've set up our maven dependencies wrong? We have several projects a,b,c and one "maven-parent" project who has only a pom.xml with this in it:
<project>
<artifactId>maven-parent</artifactId>
<packaging>pom</packaging>
<modules>
<module>../a</module>
<module>../b</module>
<module>../c</module>
</modules>
</project>
and the "a" project references "b" like so:
<project>
<artifactId>a</artifactId>
<packaging>jar</packaging>
...
<dependency>
<groupId>com.pursway</groupId>
<artifactId>plummet</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>
</project>
Thanks!
Set up each project as a separate project in Hudson and use the Hudson configuration for downstream dependant projects to build whatever is necessary depending on the scm changes.
Perhaps you should try -am -pl. From mvn --help
-am,--also-make If project list is specified, also
build projects required by the
list
-amd,--also-make-dependents If project list is specified, also
build projects that depend on
projects on the list
You can specify what Raguram has pointed out in hudson project configuration. Under the build
option you can specify Maven Goals and options.
See that in image below
http://imageshack.us/photo/my-images/696/hudsonmaven.jpg/

Resources