Jenkins + Sonar + Maven with poms in extra directory structure - maven

I have a (big) maven project with many modules which looks like this at the top
src/
maven-build/
src contains the tree with all the Java sources. maven-build contains the tree with all the poms
I can build everything fine with Jenkins, but when I add a Sonar analysis triggered through maven, Sonar complains that
[...]/src/x/y/Z.java is not in basedir [...]/maven-build
I already tried copying the Java files to the maven-build directory, but this doesn't help...
Is there a way to change the basedir on Sonar? Or can I solve this in a different way?

I copy my root-pom to the directory containing the source-directories. You could also try copying the pom from maven-build to the directory containing "src". In that way, "[...]/src/x/y/Z.java" would be within basedir.
pom.xml
src/
maven-build/

Related

How to copy all the dependencies in Maven project modules to a directory?

I have a big local maven project that contains multiple modules which are inturn maven projects and are dependent on one another.
Ex.
parent pom.xml
<pom>
<module1> #jar
<module2> #dependent_on_module1.jar
<module3> #
</pom>
I have mentioned the sequence to build those modules in the parent pom.xml .
I also mentioned where to place the artifacts when they're built in groudId and artifactId.
But in the dependencies for all those modules, I have mentioned a common local system path for all those modules.
Is there any way to copy all the artifacts which are being created for modules when maven build is performed on the parent pom to a specific directory that can be dynamically mentioned when the maven command is run.
I have searched for maven copy command. But looks like it's not going to do what I want.
Any suggestions?

Copying jar from local Maven repository

I'm working on a sort of deployment script for a Java project using Python/shell. The script currently can copy jars either from a Sonatype Nexus repository or from the project's target folder. The remote/Nexus setup seems all good, but I'm interested in instead copying from the local maven repository because allows me to always know the location of the jar regardless of where the project is installed.
I guess my question is: Am I overlooking anything by just copying the first jar from the folder ~/.m2/repository/{groupid}/{artifactid}/{version}? Or is this totally a good way to go about this?
If the groupId consists of more than one part, for example org.apache.httpcomponents , then the folder structure reflects this: org/apache/httpcomponents/...
There may exist more than one jar file inside the version directory.

Maven: Get artifact list of sub modules

I have a root parent maven module which has lot of sub-modules that build jar files as artifacts.
I cannot change all sub-module pom.xml files.
From the root parent pom.xml is there a way I can get a list of all jars (artifacts) built by sub-modules?
Preferably after the package phase is complete?
PS: As a part of root module build I want to generate a report using a tool which requires this list of jar files.
There's a target/maven-status/maven-compiler-plugin/compile/default-compile/createdFiles.lst in a Maven project.
You can use the GMavenPlus Plugin and Walking the File Tree to gather these files and put their content where you want.
Another option is to develop an own Maven plugin that does the same.

Download artifacts from local Maven Repository

Hey im new to maven and i was wondering if anyone knew if i had a bunch of files in a directory, can i make that directory a local repo for maven. the projects in there are not maven projects but would i be able to somehow downlaod those files onto another location using maven?
this is how the folder is organized:
patch
--new folder
----versions (multiple folders which contain zip files)
is there a way to getting the version folders and copying that to a different directory with a maven command like
mvn org.apache.maven.plugins:maven-dependency-plugin:2.8:copy -Dartifact=org.hibernate:hibernate-entitymanager:3.4.0.GA:jar:sources -DoutputDirectory=/home/-Dmdep.useBaseVersion=true
You were very close to the correct solution - same plugin, different mojo:
$ mvn maven-dependency-plugin:copy-dependencies -DoutputDirectory=/path/to/output
This will dump all dependencies into the location of your choosing.
The -DstripVersion=true argument is useful if you want to have the jars by their canonical name without the version suffix (ie log4j.jar vs. log4j-1.2.17.jar).
Hope that helps.

Maven release no POM in this directory

I am trying to use the maven-release-plugin 2.3.2 on a multi module POM. (Maven 3.0.4)
release:prepare works fine but release:perform fails with this error
[INFO] org.apache.maven.lifecycle.MissingProjectException: The goal you specified
requires a project to execute but there is no POM in this directory (...<workspace>/target
/checkout). Please verify you invoked Maven from the correct directory.
Now the parent POM lies inside this <workspace>/ but in the <workspace>/target/checkout there is no POM as the target directory was created by the plugin. I am assuming there should be a copy of the pom.xml here which should be created by the plugin and that is why the error.
What I am doing wrong ? Directory and POM structure attached. Module 1 and 2 both have respective pom.xmls in root.
I have looked at maven release plugin, git, and the pom's not at the top , maven generating pom file , Maven 3.0's "mvn release:perform" doesn't like a pom.xml that isn't in its git repo's root directory . They don't help as my pom already lies in the repo's (SVN) root directory and this directory where the plugin is looking for the POM is only temporary, so I cannot/should not hard-code it.
Fixed it.. wrong path in the tag in the parent POM. Comment from khmarbaise got me thinking that the path in SVN=Jenkins workspace=path in is the only way it can work and thats how it did.
Make sure you have not committed target folder in the project structure, due to which its checking out in that folder, and hence not able to find the pom file.
I faced the similar issue.:)

Resources