mvn site fails due to dependency resolution - maven

I want to run the site lifecycle after an mvn verify, but it fails.
to be precise:
mvn versions:set -DnextSnapshot=true
mvn install
mvn site
# works
mvn versions:set -DnextSnapshot=true
mvn verify
mvn site
# fails
The project is a bom-based multimodule project consisting of:
pom.xml - root bom
modules/pom.xml - has pom.xml as parent
modules/ci-lib/pom.xml - has modules/pom.xml as parent - library project
modules/ci-main/pom.xml - has modules/pom.xml as parent - uses the library project
for more details, see https://github.com/helt/ez-ci
Error details are quite obvious (mvn -X), but I wonder why the dependency resolution does not look into the project artifacts itself...
[DEBUG] Could not find metadata de.fhg.igd.iva.examples:ci-lib:1.0.3-SNAPSHOT/maven-metadata.xml in local (C:\Users\foobar\.m2\repository)
Is there a way to tell maven-site-plugin to look up all information in the respective target/ directories of this project? Any other idea how to fix it is also appreciated...

Related

Could not resolve dependencies for project, except when called with package

I have an EAR project, defined very similarly as the reference project of WildFly. In addition to that, I have another JAR project JarProject
which is included in:
parent's pom.xml (as a <module> and in its <dependencyManagement>)
the EjbProject's pom.xml (with the scope provided)
the EarProject's pom.xml (with the default scope, compile)
The problem is that when executing mvn eclipse:eclipse or mvn wildfly:deploy (from the parent project) it fails with the error
[ERROR] Failed to execute goal on project EjbProject: Could not resolve dependencies for project groupId:EjbProject:jar:0.0.4-SNAPSHOT: Could not find artifact groupId:JarProject:jar:0.0.4-SNAPSHOT -> [Help 1]
It somehow looks the JarProject in the local repository, and does not see it in the parent project.
Very important note: mvn package works without problems, as mvn package wildfly:deploy or mvn package eclipse:eclipse do, but without pacakgeing before eclipse:eclipse, it fails.
Maven version: 3.0.4 and 3.3.3
I'm not sure I got the question. Hope this will help...
Goals "eclipse:eclipse" and "wildfly:deploy" do not trigger building of your projects. To use a project as a dependency it needs to be built from the parent pom or installed in you repository.
When you do mvn package eclipse:eclipse the package triggers the build of the JarProject.
If you want do be able to do only mvn eclipse:eclipse then you need to perform a mvn install on your JarProject first.

Maven build second level+ child projects using reactor option -pl

My maven project structure is as below
Project A
pom.xml
- ProjectB
pom.xml
- ProjectC
pom.xml
- ProjectD
pom.xml
- ProjectY
pom.xml
By using maven reactor options i can
clean install -pl projectB or clean install -pl projectY
But while trying to build the second level child modules using clean install -pl projectC, maven throws
org.apache.maven.MavenExecutionException: Could not find the selected project in the reactor: projectC
how to build the second level+ child modules using maven reactor options
From the documentation for the -pl option it states the following:
-pl,--projects <arg> Comma-delimited list of specified
reactor projects to build instead
of all projects. A project can be
specified by [groupId]:artifactId
or by its relative path.
The important part for you is: "or by its relative path".
So to build projectC, you simply need to refer to it by its relative path (projectB/projectC). So the command you need is:
mvn clean install -pl projectB/projectC
This is an answer from a similar question that is also relevant here.
By using artifactIds you don't have to know the structure of your project.
If you only use the artifactIds of the given project you have to define that correctly on command line:
help output of Maven (mvn --help)
Comma-delimited list of specified reactor projects to build of all
projects. A project can be specified by [groupId]:artifactId or by its
relative path
This means in your case you have to define:
mvn clean install --projects :projectC,:ProjectY
Notice the : that is prepended to the artifactIds to indicate you omit the groupId
Just in case someone else has this one too:
I also encountered this error message. The reason was that by accident I had been in one of my (sub-)modules in the path in terminal.
Of course the command has to be executed in the project's root hierarchy. According to the example above you have to assure that you execute a command like:
clean install -pl projectB
at Poject A
not e.g. at ProjectY or somewhere else deeper in the project structure.
Correct:
user:~/workspace/IdeaProjects/pojecta{master}$ clean install -pl projectB
Wrong:
user:~/workspace/IdeaProjects/pojecta/projecty{master}$ clean install -pl projectB

Where to add dependencies in MAVEN multi-module project

I am trying to make sense of all the dependency thing in maven multiple module projects. As a starting point I used appfuse to create a new spring mvc multi-module project. It initially has web and core modules.
I found the knowledge of deploying this project. But when I get an error. I am confused of where to add a dependency or a plugin always. I would like to clarify with the following issue.
I created a appfuse mvc multimodule project. I maven installed the core and then maven jetty7:run on web (initially I ran mvn install on root folder and then I tied to mvn tomcat:run on the same folder. But it has to be done as below.
mvn install on core folder
mvn tomcat7:run on web folder
I initially got an error like missing prefix "Tomcat7". I resolved it by adding the following plugin to the pom in web.
<plugin>
<groupId>org.apache.tomcat.maven</groupId>
<artifactId>tomcat7-maven-plugin</artifactId>
<version>2.0</version>
</plugin>
And that error was resolved. But I was unsure about that because I can add the plugin to the parent pom. Then I ran again mvn tomcat7:run on web file and now I am getting the following error.
[INFO] >>> tomcat7-maven-plugin:2.0:run (default-cli) # test-web >>>
[WARNING] The POM for org.aspectj:aspectjweaver:jar:1.8.0.M1 is missing, no depe
ndency information available
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
I am not sure where to add the dependency to which pom. I would like know some basics of how the poms can work together to do the installation. For example, There is also a parent pom. But I am not doing a mvn install or anything on the parent pom. I am going to the core and do a mvn install and then go to the web and do a mvn tomcat7:run
I this case how the parent pom contribute to the installation and ruining process? and how should I resolve the above warning and resolve the error.
Some informative answer is very much appreciated. Thanks
You should add the Tomcat plugin to the web project as it will only work in a project that's type "war". There should already be a jetty plugin configured, so "mvn jetty:run" should work from the web folder.

"mvn clean generate-sources" could not resolve dependencies

there
I met a weird problem. I have a multi-modules enterprise project that is built in Maven. I setup the project hierarchy like this
parentPom
--MyEar (packaging ear)
--MyUtilJar (packaging jar)
--MyEJB (packing ejb)
--MyWeb (packaging war)
In the MyEJB project, the pom.xml actually binds the apt plugin to the generate-sources phase to generate some java codes. MyEJB depends on MyUtilJar project.
My problem is that when I execute the mvn clean compile, everything works fine. But if I execute mvn clean generate-sources instead, it throws error, complaining it cannot resolve dependency for artifact mygroup:MyUtilJar:jar:1.0.
How can I solve this issue?
In order for the generate-sources to work, you need to have all dependencies in a repository - your local one or a remote one. Just having the dependency in a folder near where it's needed won't work.
Try building and installing the until to put it in your local repository then running the generate-sources.

Maven-ear plugin: could not resolve dependencies to ejbModule

I am probably missing something but how is the maven ear plugin (I'm using version 2.5) resolving ejbModule dependencies? I have the following structure:
my-parent (multimodule)
-- pom.xml
-- myEar
-----pom.xml
---myEjb
-----pom.xml
In the ear I have the dependency to myEjb.
2 things that are unexpected when i execute mvn package under myEar
It does not build (package) myEjb.
It does try to resolve the depedency to myEjb via repository, which is in our case our custom sonar repository that we configured in settings.xml. I would like not to have to install myEjb to our custom sonar respository in a separate step.
What I expected from the plugin would be: check the ejbModules dependencies, build and package them if not done or something changed, copy the jar to the target directory of the ear project and package the whole thing correctly.
Obviously I am missing something though, anybody can enlighten me?
Based on your structure you have to build from the root of your project which means you have to change to my-parent directory
my-parent (multimodule)
-- pom.xml
-- myEar
-----pom.xml
---myEjb
-----pom.xml
and do
mvn clean package
The behaviour you described that maven tries to solve the dependencies against your local repository is the usual process. You can do partialy building a single module within a multi-module build but in your case this won't work cause you depend on your myEjb which neeeds to be rebuilded. Otherwise you can do a
mvn install
first and after that you can do from the root:
mvn -pl myEjb clean test
which will only build the myEjb module and uses the dependencies from the repository (localy in this case).

Resources