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

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.

Related

mvn site fails due to dependency resolution

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...

Maven default evaluation of the pom xml file

We do not have project design in parent and module way.We have project A and project B . Project A has dependency of project B . we passing the version of the dependency jar by command prompt in eclipse, Its compiling and install properly. but its pom shows always error.and error is like
Missing artifact
com.testdependency:testdependency:jar:org.apache.maven.model.Build#5ae16e48
Passed the build parameter by command line like -Dbuild. Is there any way resolve this ?
pom.xml would need the dependencies present in your local .m2 repository. If you don't install the dependencies to your local repository, pom.xml can't find them. So, run a build on your dependency project with goals selected as clean install, which should insall the artifact to your local repository. Then in your eclipse, right click on the main project and execute Maven -> Update Project. This should resolve your issue.
Refer to this link for the details on the repositories

Running maven multi-module failsafe tasks independently from mvn clean package

I have a multi-module project a. Sub-module x includes an a simple integration test which requires also a dependency on sub-module y.
I would like to be able to separate the compilation and package phase from running the tests. When I run the following command, the integration test run successfully
mvn clean verify
When I run the following command, it fails
mvn clean package && mvn failsafe:integration-test failsafe:verify
[ERROR] Failed to execute goal on project x: Could not resolve dependencies for project a:x:jar:1.0-SNAPSHOT: Could not find artifact a:y:jar:1.0-SNAPSHOT -> [Help 1]
The underlying reason is that I would like to run the unit-tests and various integration tests each in separate jenkins tasks after the compilation completes (without running compile and package phase again). Reproducible code is here https://github.com/itaifrenkel/failsafe-test. Using Maven version 3.2.1.
Clarification: I cannot mvn install on jenkins machine since I have concurrent builds of different git versions (that have the same maven version).
When you execute mvn clean verify, the build succeeds: Maven resolves the y dependency because it is in the same project reactor and y was packaged successfully into a jar inside this reactor. If you take a look at the log, you will notice that this command triggered the maven-jar-plugin, which is expected since this plugin is bound to the package phase and verify phase comes after it in the build lifecycle.
The command mvn clean package && mvn failsafe:integration-test failsafe:verify actually executes 2 commands. First, mvn clean package will succeed and package the application (same reason as before: y is in the reactor and is packaged into a jar).
However, for the second build, mvn failsafe:integration-test failsafe:verify, since y was not packaged into a jar inside the reactor, Maven can't resolve the dependency directly so it needs to look for it in the repository. Since this artifact was never installed in the repository (and is obviously not available in Maven Central), the dependency can't be resolved, hence the error message
As such, you have 2 possible solutions:
Install the y dependency into the local repository with mvn install:
mvn clean install && mvn failsafe:integration-test failsafe:verify
Running jar:jar before the integration tests so that Maven can resolve the y dependency. This does not rebuild the project: it makes the assumption that the project was already built before by simply asking maven-jar-plugin to make a jar out of the result of the previous build.
mvn clean package && mvn jar:jar failsafe:integration-test failsafe:verify

"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