I have a Maven aggregator project like this:
/pom.xml
/module-A/pom.xml
where in the /pom.xml, there is a
<modules>
<module>
submodules/functional
</module>
</modules>
In the parent project, I also have many classes and tests written. They properly packaged in to the artifact. However, when I run mvn test only the child module's tests are executed.
To be more specific. We are managing child modules using git submodule and it does not have any dependency on the parent module. I do not know any other way to refer to the submodules without involving a Maven repository.
I tried many ways to run them and none of them works. Is there a way to test source code in the parent module?
Related
My parent pom modules list looks something like this:
<modules>
<module>jarProject1</module>
<module>jarProject2</module>
<module>jarProject2</module>
<module>warProject1</module>
<module>warProject2</module>
</modules>
I would like warProject1 and warProject2 to be ignored when I run mvn clean install on the parent pom. I want install to only build jars and put them in the maven repo but not the war producing projects. Currently I do it using profiles but I have some problems related to that. I would like the parent pom to keep a comprehensive list of modules in its default modules tag and not under profiles. Is there a way to do it and how?
I have a multi-module POM file:
...
<modules>
<module>../project1</module>
<module>../project2</module>
<module>../project3</module>
...
</modules>
...
Each of the modules is itself a Maven project with its own POM. Inside each of these POMs I have the scm tag defined with the developerConnection specified like this:
<scm>
<developerConnection>scm:svn:svn://hostname:port/path/to/trunk</developerConnection>
</scm>
My goal is to run the following Maven goals/options:
versions:update-parent versions:commit scm:checkin \
-Dmessage="automated commit" -Dusername=user -Dpassword=pass
My expected results are:
The parent of each module's POM is updated to the latest released version.
The changes to each POM would be checked in to the SVN path specified in the POM for the module. E.g. project1 POM checked in using project1 <scm>/<developerConnection> path, project2 checked in using project2 path, etc.
Actual Results:
The parent of each module's POM is updated to latest released version. This works as expected.
Only the multi-module POM is checked in to SVN, none of the module POMs are checked in. This is the problem.
Is there a way to achieve the expected results above or is this something that the SCM plugin simply was not designed to do? If it is possible, how would I modify what I have in order to get the results I want?
Note: I can't change the project structure - I can't put the modules inside of the parent project, they have to remain separate.
Not sure if it's relevant but I'm using Maven 3.3.9.
I have a parent project with around 20 child modules:
<project>
<modules>
<module>module-1</module>
<module>...</module>
<module>module-20</module>
</modules>
</project>
I would like to use this project as one single entity, with all 20 modules included, in other projects. What is the convenient way to do this in Maven?
Should I make a new child module which imports the other 20 modules and refer to this project? Should this be a JAR or a POM project?
<project>
<packaging>jar</packaging>
<dependencies>
<dependency>... module-1 ...</dependency>
<dependency>...</dependency>
<dependency>... module-20 ...</dependency>
</dependencies>
</project>
I think the way you mentioned in your question is a good idea. It is actually mentioned as a best practice in the Maven book, quoting:
If you have a set of dependencies which are logically grouped together. You can create a project with pom packaging that groups dependencies together.
You can create a new module called module-all, which would be of pom packaging, that simply has a dependency on each of the modules. The packaging should be pom because the primary artifact of this module will only be the pom.xml (there will be no sources to compile, no JAR...). Then, in your external projects, you can simply add a dependency to this new module (as <type>pom</type>) and every module-i dependencies will be included transitively.
There would be a cave-at if all of your modules did not share the same version: there would need to be a reference to a specific version of a specific module and you would have to update the module-all version each time a module's version changes. However, if they all share the same version, module-all release cycle would be in line with module-i's.
I have a project with a couple of dozen Eclipse plugins, all inter-related and living in different subfolders. The build was converted to a multi-module manifest-first Tycho build a couple of years ago and it works quite well.
One of the plugins is rather key, and can also be built as a standalone Java app, which doesn't use an Eclipse runtime. Currently it has its own POM file (pom-standalone.xml) so that Jenkins can build the standalone app separately and the Tycho build knows nothing about it - the pom-standalone just lists the previously-built plugin jars (thanks Tycho!) and Eclipse libraries that it needs as dependencies. Couple problems with this approach though:
I cannot easily use IntelliJ to work on the standalone project with Maven dependency management, because it doesn't recognize the custom pom-standalone.xml filename as a POM.
The many jars that this project relies on are checked in to the project for the sake of Tycho and the Eclipse Manifest file, but they're also managed by Maven for the standalone build. So any dependencies have to be added to the pom-standalone.xml file AND entered into the OSGi manifest AND checked in to the source control for Eclipse purposes.
It seems like a straightforward workaround would be to tell Tycho/modules to use something other than pom.xml for the submodule's POM, or perhaps all the multimodule POM files, since Eclipse doesn't use those anyway - then the pom-standalone.xml can be converted to pom.xml and then IntelliJ will be fine with it.
I know you can specify the -f attribute to Maven builds, but will that really apply to all submodules? Can you specify the POM filename for just ONE submodule?
Are there alternative solutions? Eclipse/Tycho/p2 builds seem somewhat of a headache requiring manual library management and checking in libraries to source control, but maybe there have been changes I'm not aware of in the Eclipse build world the last few years.
Found a Similar Question that didn't help much.
You can include projects in an aggregator POM by specifying the full name to the POM file with custom name. Example:
<modules>
<module>org.example.bundle1</module>
<module>org.example.bundle2</module>
<module>org.example.keybundle/pom-tycho.xml</module>
</modules>
This both works in a pure Maven and Maven/Tycho build.
To extend #oberlies answer a little bit:
SCENARIO: top aggregation POM comes in multiple flavors, so any style can be built from the top.
<!-- in file pom.xml -->
<modules>
<module>org.example.bundle1</module>
<module>org.example.bundle2</module>
<module>org.example.keybundle</module>
</modules>
All submodules will be built using their standard pom.xml
and
<!-- in file pom-tycho.xml -->
<modules>
<module>org.example.bundle1/pom.xml</module>
<module>org.example.bundle2/pom.xml</module>
<module>org.example.keybundle/pom-tycho.xml</module>
</modules>
Submodules will be built using the specifically named POM file.
and, likewise:
<!-- in file pom-special.xml -->
<modules>
<module>org.example.bundle1/pom.xml</module>
<module>org.example.bundle2/pom-special.xml</module>
<module>org.example.keybundle/pom-tycho.xml</module>
</modules>
Submodules that have custom POM files use them, and others state they still want the normal POM file, all independent of the name of the top aggregation POM file.
Because mvn -f pom-tycho.xml assumes that file name in all submodules. So if you do want pom.xml in any submodule when the top file isn't named pom.xml you need to fully specify for each submodule.
I have a project that is built in the next manner:
parent module named Production, it holds two modules named apps and libs, each of them holds various projects.
Production
apps
common
utils
libs
api
dev
Production pom
<groupId>com.prod</groupId>
<packaging>pom</packaging>
<modules>
<module>libs</module>
<module>apps</module>
</modules>
Apps pom
<parent>
<groupId>com.prod</groupId>
<artifactId>apps</artifactId>
</parent>
<modules>
<module>common</module>
<module>utild</module>
</modules>
Where packaging of Production, apps and libs is pom.
While the packaging for the rest is war/jar.
When I try to run mvn install on Production (or any other module/project) I get Non-resolvable parent POM: Failure to find
Only when I run mvn install -N on Production, apps and libs, I can finally start working with the projects.
Is there a better way to accomplish successful modules and projects alignment without running mvn install -N? some pom definition or some other solution?
Without seeing your POMs, I am guessing that you are missing <module> elements naming the children in Production, apps and libs POMs.
Once you have that, if everything else is in order, you can build from the Production folder with mvn install and have the reactor figure out what the right order to build the various modules are, subject to inter-module dependencies. Note that the <module> elements are relative paths to the child projects, not anything to do with the GAV of the project.
See http://books.sonatype.com/mvnex-book/reference/multimodule.html for more information about proper setup for multi-module projects.