Maven Modules + Building a Single Specific Module
Any best practices here?
Use the Maven advanced reactor options, more specifically:
-pl, --projects
Build specified reactor projects instead of all projects
-am, --also-make
If project list is specified, also build projects required by the list
So just cd
into the parent P directory and run:
mvn install -pl B -am
And this will build B and the modules required by B.
Note that you need to use a colon if you are referencing an artifactId
which differs from the directory name:
mvn install -pl :B -am
As described here:
- Define modules list which shall be build in Maven multiproject build
How to build a module separately in multimodular maven project?
The flatten-maven-plugin
solves the problem.
Thanks to @khmarbaise, who adviced in the comments reading the docs to the end.
Adding the plugin to /modules/base/pom.xml
solved the problem with building a submodule separately:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>flatten-maven-plugin</artifactId>
<version>1.2.5</version>
<configuration>
<updatePomFile>true</updatePomFile>
<flattenMode>resolveCiFriendliesOnly</flattenMode>
</configuration>
<executions>
<execution>
<id>flatten</id>
<phase>process-resources</phase>
<goals>
<goal>flatten</goal>
</goals>
</execution>
<execution>
<id>flatten.clean</id>
<phase>clean</phase>
<goals>
<goal>clean</goal>
</goals>
</execution>
</executions>
</plugin>
Before starting a phase on facade
module, it is required to have base
and core
in the local repository, so maven could find the artifacts. Hence, here is the sequence of actions in root:
mvn install -pl modules/base,modules/core
(or justmvn install
)mvn package -pl modules/facade
How to compile a single module inside it in a multi-module maven project?
Instead of launching goal "package", launch goal "install" on the root pom (or just moduleB). This will place moduleB in the local repository (~/.m2/repository) and Maven will be able to fetch it when it compiles only moduleA. Then you'll be able to compile only moduleA.
How to Build specific module in a multi module spring-boot maven project
You need to tweak your pom
.
Parent pom:
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<skip>true</skip>
</configuration>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
Module pom (containing your Main)
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<mainClass>Your mainClass</mainClass>
<fork>true</fork>
<skip>false</skip>
</configuration>
</plugin>
</plugins>
</build>
Pay emphasis on Configuration > skip
Maven: How to run module before building other modules in multi-module project?
I understand that just by changing the order of the modules in the pom file I can get the module to build before the others, but how do I run it before building the rest of them?
Ordering of modules will not necessarily build them in that order. If one module depends on another then you must handle it through <dependency>
in the pom of the dependent project.
To answer your question, build the REST service module first and deploy it to your server/container. In multimodule projects running command like mvn somegoal
will run somegoal
on all the modules.
To run different goals on modules, try in two steps mvn -pl module1 somegoal
mvn -pl module2 someothergoal
In your project they will take the form of mvn -pl RESTModule deploy
followed by usual
mvn command for running test for other modules. Remember the -pl option for these too.
Edit: After looking at the requirements from your comment I tried one more solution. Might work for you as well. Add maven-deploy-plugin to the pom of REST Module and tie it to a phase such that only the RESTModule project deploys the artifacts but not others (since they don't have such plugin in their pom). snippet to be added.
`
<project>
<build>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-deploy-plugin</artifactId>
<version>2.8.2</version>
<executions>
<execution>
<id>MyProjId</id>
<phase>package</phase>
<goals>
<goal>deploy</goal>
</goals>
</execution>
</executions>
</plugin>
</build>
<distributionManagement>
<repository>
<id>my-repository</id>
<url>http://path/to/your/repo</url>
</repository>
</distributionManagement>
</project>
and run the project using the parent pom in jenkins.
Maven - build just a few modules from a multi model project
Something like mvn clean install -pl microservice-a -am
to build the microservice-a
together with its dependencies.
Related Topics
How Come Invoking a (Static) Method on a Null Reference Doesn't Throw Nullpointerexception
How to Add Directory to Classpath in an Application Run Profile in Intellij Idea
How to Use Cardlayout with Netbeans Gui Builder
How to Respond with an Http 400 Error in a Spring MVC @Responsebody Method Returning String
How to Use Jaroutputstream to Create a Jar File
Java Unsupported Major Minor Version 52.0
How to Read and Copy the Http Servlet Response Output Stream Content for Logging
Why am I Getting Java.Lang.Illegalstateexception "Not on Fx Application Thread" on Javafx
Programmatically Getting the MAC of an Android Device
Selenium Webdriver How to Resolve Stale Element Reference Exception
How to Resize an Image Using Java
Java Sslhandshakeexception "No Cipher Suites in Common"
How to Find Unused/Dead Code in Java Projects
Natural Sort Order String Comparison in Java - Is One Built In
What HTML Parsing Libraries Do You Recommend in Java