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.
Related
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
I have multiple questions.
Can I specify the pom.xml in mvn command?
Can I mix the goals of another project while executing mvn command on current project ?
Eg: mvn clean-otherproject comple-otherproject instal-otherproject compile-thisproject
I can do this with multiple mvn commands, but Can I do this in single maven command.
Just mvn --help would have answered the first question:
mvn -f otherPomFile.xml
No. You can simple execute the phases for the current project you are in. You can give multiple phases like
mvn clean install site site:deploy
For the first question, see khmarbaise's answer
If you want to build more than one maven project in one step, you must use modules.
In a multi-module project, if you call mvn install from the top project, all sub modules are built, unless you use the advanced reactor options (e.g. mvn install -pl util -am only builds the module 'util' and it's dependencies)
I have a project with a complicated ant build that we would like to remain as ant at the moment (will be converted to maven eventually).
I am using jenkins at the moment to build/test our application. After build/test, I now want to push the built artefact to a Nexus repository.
For a Maven project, I can use the post build action "Deploy Artefacts to Maven Repository" to do this.
Whats the best way to structure my Jenkins jobs to achieve an ant build and then deploy the code to Nexus?
Have you seen the example Ant scripts in the Sonatype website?
They actually include pushing artefacts to Nexus:
http://central.sonatype.org/pages/apache-ant.html#signing-and-deployments-using-the-maven-ant-tasks
Or there is also some more docs at Sonatype:
http://books.sonatype.com/nexus-book/reference/staging-deployment.html#staging-ant
I have a "commons" library that I install to my local repo using mvn install. That library provides common company stuff used in different, not connected projects.
So I include that library as a maven dependency. And when I run mvn package on the final projects, there have been days where I forgot that I have to explicit install the commons library to get the changes picked up during package of the implementation projects.
Is there any chance I could trigger/invoke install of a different project during package?
You will have to use Antrun maven plugin, and execute shell command using ant while running properr lifecycles of maven build.
Here you have some details on configuration
http://maven.apache.org/plugins/maven-antrun-plugin/
If repository manager or external scripting (Ant) is not an option you could tweak your project structure. You could introduce an aggregator maven project which will run modules in a predefined order:
<packaging>pom</packaging>
...
<modules>
<module>[path to commons project]/commons</module>
<module>[path to your module project]/module</module>
</modules>
So whenever you want to build your project you build this aggregator project instead.
I have a Maven Java project with many modules and one meta-modul. And I want to run test. I use: mvn test command in console. But my test fails when compilation, because classes in other modules are not found. But in IDE Eclipse no errors. How can I fix that?
if you have well defined dependencies, use mvn install instead of mvn test. Running tests is included in install phase too and you'll get the modules you need for compilation into local maven repository.
Try to run mvn install. This compile, packages and runs tests. Then when everything is compiled you can probably run mvn test only. But you should not (IMHO) because only when you are running the full process you are sure that the newest versions of your classes are being tested. Do not worry about efficiency: maven does not compile classes if it already have them compiled. Only mvn clean install will rebuild everything from scratch.
Your models need to be free of dependency cycles!
Try to run mvn test from the folder where the parent pom is located.
(details)
If you do not have a parent pom with sub modules. Then you must first run mvn install for all the other of your modules where the module you want to test depends from.
(Eclipse does not need this, because it can resolve dependencies to other open projects directly)
But if all the modules belong to an single release cycle (all the modules will be released togeter with the same version) then it is may a better approach to use parent and child modules/pom -- because then you can run mvn test or mvn install for the parent pom, and maven will do it for all the childs in the right order. -- After you have installed all other modules, you can run mvn test on a single module until you update an other modul. -- Then you will need to install this updated modul too, or better run install for the parent.