Configuring Delta build in Java Maven project - java

My project is structured with a Parent POM and lots of modules each having child POMs themselves. Currently I'm doing a maven build with my Parent POM which is building the entire project. How can I convert this to a delta build i.e. I want to build only the module which has changed files?
I'm unable to find any plugins suiting this need.
Another approach is writing a script to find the deltas and build individually.
Can someone please advise.
Thanks in advance.

Slightly unrelated but if you know which module you are working on you can use Maven reactor to build this module with related dependencies by running:
mvn install -pl :my-module -am
-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

Related

sonar-maven-plugin with two-step build process

I have a multi-module maven project that needs to be compiled in two steps: first some modules, then the remaining modules (for the record, the project uses Eclipse Tycho to build and uses both "pom-first" and "manifest-first" modules that cannot be mixed in the same reactor build. Cf. https://wiki.eclipse.org/Tycho/How_Tos/Dependency_on_pom-first_artifacts).
I then use 2 maven profiles to split the modules, and I compile the whole project with something like:
mvn clean install -Pprofile1
mvn clean install -Pprofile2
I would like to analyze this project using sonar-maven-plugin, but with a single SonarQube project. Is there a way to do that?
Thank you for your answers.

Maven build failure from missing tycho dependency?

I'm attempting to build two Maven projects from Eclipse. One project constitutes a set of dependencies and libraries to be used for the other project which contains all of my source code. Both are configured as Maven projects using Tycho 1.0.0 .
I have a parent POM file that contains three modules: a folder containing my target file, the plugin containing the dependencies and the plugin that contains the source code. When trying to maven build on the parent POM, I get the following error:
Failed to execute goal org.eclipse.tycho:tycho-compiler-plugin:1.0.0:compile (default-compile) on project com.ericsson.cd-editor.ui: Execution default-compile of goal org.eclipse.tycho:tycho-compiler-plugin:1.0.0:compile failed: A required class was missing while executing org.eclipse.tycho:tycho-compiler-plugin:1.0.0:compile: freemarker/template/Configuration
Gonna post the full error log in pastebin since it's diffcult to read in a Stack Overflow post:
http://pastebin.com/EYnsqvpJ
Here is my parent POM file:
http://pastebin.com/wSAtwspV
I've been told by a colleague of mine that the reason this might be happening is that this dependency might be used by Tycho and cannot be found. The freemarker package is however available in my .m2/repository/.
It's really hard to tell where the error might be.
First, make sure the jar you have in your m2 archive actually contains the class the compiler is looking for.
You could check whether you dependencies are in the central maven repository, instead of making a project containing them.
Does the project that needs all the dependencies state them explicitly, e.g., in feature.xml or Manifest.mf? Otherwise tycho will not load them, even if they are accessible to maven.
Posting the pom.xml files for the modules might be helpful. Hope you'll figure it out :)

Unable to build Shopizer project

When I execute the mvn install inside the project sm-core of Shopizer, I am getting the below error:
[ERROR] Failed to execute goal on project sm-core:
Could not resolve dependencies for project
com.shopizer:sm-core:jar:2.0.3-SNAPSHOT: The following
artifacts could not be resolved: com.shopizer:sm-core-model:
jar:2.0.3-SNAPSHOT, com.shopizer:sm-core-modules:jar:2.0.3-SNAPSHOT:
Failure to find com.shopizer:sm-core-model:jar:2.0.3-SNAPSHOT
in http://maven.springframework.org/snapshot was
cached in the local repository, resolution will not be
reattempted until the update interval of
org.springframework.maven.snapshot has elapsed or updates
are forced -> [Help 1]
How can I solve it?
The Shopizer project is actually a multi-module Maven project. This means that it has a root pom.xml of packaging pom and declares several <modules>.
Those modules, which are Maven project themselves, are typically found as sub-folders under this root folder, which is the case here: there are 4 sub-folders, which are exactly the 4 Maven modules. To compile those sort of projects, you need to invoke Maven from the root project, in this case, shopizer.
You may ask why. In a multi-module Maven project, there is generally inter-dependencies: one module is dependent on another. In this case, the scm-core module that you're trying to build has dependencies on both sm-core-model and sm-core-modules, which are two modules of that project. So when you're building it, Maven will try to look in your local repository those artifacts. The problem is that it won't find them: they have never been built before. Maven won't also find them on a public repository because we're dealing with SNAPSHOT dependencies. The solution is to start the build on the top project: Maven will order correctly the reactor so that when it builds scm-core, both those dependencies will have been built.
Put simply: in a multi-module Maven project, you should practically always invoke Maven commands from the root POM.
To solve your problem, you can check-out the 2.0.3 branch (which is the latest branch) and invoke mvn clean install on the root POM. I did just that successfully.

maven - using local source instead of external dependency

If someone could help me out here it would save me a lot of time.
I maintain an open source library that gets pushed out to a sonatype repository. I make changes to that library a few times a day and push it out to the 1.0_snapshot build using mvn deploy.
Let's call it project1
I work constantly in another project that uses that library let's call it project2.
Right now, whenever i make changes to project 1 or 2, i need to first build and deploy project 1 to the repo, then build project 2 so it downloads a fresh copy of project1.jar
Project2 has Project1 as a dependency in a pom.xml:
<dependency>
<groupId>com.group</groupId>
<artifactId>project1</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
in order to build in a way where all of my changes can be tested, I have to do something like this:
mvn -f ./project1/pom.xml clean deploy
mvn -U -f ./project2/pom.xml clean package
this uploads my project1.jar to sonatype, then project2 downloads the new snapshot and builds it.
This is a simplified picture of what i'm doing on a larger scale, where my compiles take 5 minutes of up and downloads.
Question: What is the proper way to use maven so it knows to use the source of project1 in a dependency in project 2?
IDE:
install m2e in eclipse
import your both projects into workspace
from consumer project (right click > maven > enable workspace resolution)
this will put project2's classes in classpath from its target/classes instead of the actual jar
native straight maven:
You can create a maven project tree, if this two are open source project going through same build cycle it must have one already, if they are not related but related for your usecase then you can temporarily create a maven tree on top of these 2 projects and build the top parent it will build from bottom up in one command
it will find the leaf project, build it install it in maven's cache and now while building projectA it will refer it from maven's cache so no need to deploy to sonatype
You can also point project2 to build using offline mode :
mvn -o package
Then you drop the upload part of the project1 build to the remote repo.
Check the following link: Intro to repositories and How do I configure Maven for offline development?

Why does maven site:site fail in a multi-module project?

I have a Maven-3 multi-module project:
/root
pom.xml
/bar
pom.xml
/foo
pom.xml
Module foo depends on module bar, and they both have the same parent: root. Everything works fine, until I decided to clean my local repository and run mvn site:site. Build fails with a message:
Failed to resolve artifact.
Missing:
1) com.XXX:bar:jar:1.0-SNAPSHOT
It is a known bug or I'm doing something wrong? I didn't configure maven-project-info-reports-plugin anyhow in any pom.xml yet.
If you do site:site, you are running the specific site goal and not the build cycle, thus the project will not build, and since you just cleaned the repository, the artifact will not be there anywhere to use.
See following links for more information about build lifecycles in maven:
http://www.sonatype.com/books/mvnref-book/reference/lifecycle.html
http://www.sonatype.com/books/mvnref-book/reference/lifecycle-sect-package-specific.html
Perhaps you should try goal site:stage on the root/master-pom.
I didn't try this with src/site in the childs, cause i only have a src/site in the master.
But this work fine for me with Maven 3.0 and a menu ref="reports" in roots site.xml and
putting maven-project-info-reports-plugin in the childs pom.xml

Categories