maven, package without recompile a module - maven

I have a war module (C) that depends on two other modules (A,B). When I change A and do repackaging for C mvn package then B got recompiled as well (although nothing in it changes), and takes a lot of time. How do I tell maven to skip that?
Tks.

Use the new compiler plugin version 3.1. It conducts an incremental compile which works marvellously for me. It does a complete compile when it finds changes in a module, else it does not compile anything.
http://maven.apache.org/plugins/maven-compiler-plugin/compile-mojo.html
Incremental mode is the default, so in fact there is nothing else to do than updating the version!
Of course you should not perform a clean in advance. This would lead to a full compile always.

Remove B from the project by excluding it from the relevant parent POM. You could do so in a development profile. This way, it is loaded from the maven cache rather than recompiled every time.

You can also use the option -pl. Pl stands for "project list". You type
mvn -pl myProjA,myProjB clean install
This would build only those two projects. But beware, you might oversee necessary projects to build.
http://java.dzone.com/articles/5-maven-tips
I was not able to find this on the maven docs, but I'm sure it's there, too.

Related

how to make `mvn package` aware that it has already built the target

In a makefile, I can easily do something like
${target}: ${sources}
mvn package
Where I have ${target} the generated jar file, and ${sources} all the java files and the pom.xml. With this makefile, the target will not be be rebuilt unless one of the sources is changed since the last build of the target. The result is
$> make target/demo-0.8.0-SNAPSHOT-jar-with-dependencies.jar
make: 'target/demo-0.8.0-SNAPSHOT-jar-with-dependencies.jar' is up to date.
But just mvn package will always run the maven-assembly-plugin even though none of the source files has changed.
Question:
Is there a way to make mvn package be aware of the source files, similar to how make knows this so it'll just say "no need, it's already built."
Whether or not something makes sense is maybe up to the use case and the developer.
In a system where integration is far more complicated than passing unit tests the only way to gain confidence is by deploying into a test Kubernetes environment.
Anyway thanks for answering my question that the maven packaging plugin is unable to handle this dependency tracking.

Make maven output show progressed sub-modules only

I am working with an automatic build script in maven 3.x. The parent project contains of more than 60 modules. The compilation is done in a shell script simplified this way:
for each module:
cd module
mvn clean install > compile.$module.log
echo "Compiled $module"
I like to see a list of compiled modules in order to see the progress or the build. I like to have a big maven command and avoid the manual for loop. I hope to speed up the build this way, since splitting the parent project into more independent modules is not a short time option, yet.
The --quiet flag might be enough already. Alternatively a user defined logging implementation would be fine as well, as described in the manual (https://maven.apache.org/maven-logging.html)
The questions are:
What is the prefered way to modify maven log output?
Does anyone already know a ready-to-use plugin for my purpose?
Thanks

Moving files between build chain builds

What is the set up required to move files between builds in TC? I am needing to move both modified source files and build binaries between the build configurations of a build chain.
I have 1 project with 4 builds. The builds are
Update Version Number (This build updates 15 sources files)
Compile (This build compiles a dozen objects)
Test (This build runs a regression test)
Create Package (This build creates a setup.exe file)
Information about the TC setup and chain
I am using perforce as my VCS.
All 4 builds use the same VCS root.
On all 4 builds under version control settings I have "Clean all files before build" set to "On".
"Update Version Number" build is triggered by any check in to the VCS. (This works)
I have been able to successfully chain and trigger the builds. However each build starts with a fresh copy of files from the VCS.
The chaining is set up to use snapshot dependency.
Based off of the TC documentation it looks like I should be using snapshot dependency and not artifact dependency. If I put the build steps of all the builds into the same build everything works. However we are looking to have more flexibly and expand on this build chain in the future.
I tried setting up the configuration so only the first build is attached to the VCS root and the other builds don't have any VCS root. This didn't work.
I have been unable to find the answer googling but I have been able to find someone else who is struggling with this problem. Sadly they didn't receive an answer.
After speaking with TC customer support I learned the correct technique is to use both artifact dependency with "build from the same chain" selected and snapshot dependency.

Maven test scope dependency change does not recompile module's tests

We have a maven multi-module project in which the following weirdness occurred:
module-x has a TEST (src/test/java/...) which depends on code provided by module-y, whose code is not otherwise used in module-x (i.e. nothing in src/main/java/... depends on module-y)
module-x therefore defines a dependency on module-y, but with <scope>test</scope> and uses that code in one of its tests
someone changed a constructor in module-y and committed the code that broke the module-x test (as it was using the old constructor parameters)
TeamCity ran java org.codehaus.plexus.classworlds.launcher.Launcher -f app-parent/pom.xml -B integration-test when it saw the commit
the build succeeded because maven did NOT recompile/rerun module-x TEST code, it just recompiled module-y and everything that depends on it with default compile scope
I'm sure people will point out, why is that test even in module-x, etc, but this weird setup aside for a minute. What I want to understand is this:
If some project (module-x) has a test dependency (module-y) that changes and is recompiled, should not maven then notice this and do a fresh "test-compile" for the project (module-x) that "test-depends" on what changed (module-y)? Is what I saw here normal behavior?
EDIT: from comment replies it seems like the fact that TeamCity is being used may be a factor; I clarified the command used in the sequence list above.
EDIT 2: I should note that the parameter "-f app-parent/pom.xml" is actually the main module that basically depends on "the world" and is where one would run from command-line "mvn test" or "mvn clean package" to rebuild everything.

Maven for multiple modules

How do I run selected modules using parent pom in Maven like I have
<module>APP_1</module>
<module>web_1</module>
<module>service_1</module>
<module>schema_1</module>
<module>APP_2</module>
<module>web_2</module>
<module>service_2</module>
<<module>schema_2</module>
sometimes as developer if I want to build first module only so how should I achieve this task in parent pom?
First you have to make a decision.
Assuming that some of your child modules depend on other child modules you have to decide if you want to:
a) build one or more modules by themselves using the last built version of the dependent modules located in your ~/.m2/repository directory. This is super useful if you want to, say, rebuild the web_2 module which depends on the service_2 module, but service_2 is currently busted and won't compile. In this case do this:
mvn clean install --projects module-directory-name
or
b) you want to build a module and have maven recursively check all dependent modules to see if they need to be rebuilt. This is slower and safer typically. This command is:
mvn reactor:make -Dmake.artifacts=com.yourgroup:module-name
I use both of these at different times every day.
mvn reactor:make -Dmake.folders=barBusinessLogic
as described here

Resources