Gradle cannot resolve dependency - gradle

In my build.gradle file I have a line in dependencies:
compile group: 'org.jboss.seam.validation', name: 'seam-validation-api', version:'3.1.0.Final'
When I try to run the project, e.g. 'test' task, I get an error:
> Could not resolve org.jboss.seam.validation:seam-validation-api:3.1.0.Final.
Required by:
com.smspl.mc5:mc5-web-ui:1.0.0-SNAPSHOT
com.smspl.mc5:mc5-web-ui:1.0.0-SNAPSHOT > com.smspl.mc5:mc5-common-rest:1.0.0-SNAPSHOT
> Could not parse POM /Users/amorfis/.m2/repository/org/jboss/seam/validation/seam-validation-api/3.1.0.Final/seam-validation-api-3.1.0.Final.pom
> Unable to resolve version for dependency 'javax.enterprise:cdi-api:jar'
> Could not parse POM https://nexus.softwaremill.com/content/groups/smlcommon-repos/org/jboss/seam/validation/seam-validation-api/3.1.0.Final/seam-validation-api-3.1.0.Final.pom
> Unable to resolve version for dependency 'javax.enterprise:cdi-api:jar'
I'm aware that the problem is that version of 'javax.enterprise:cdi-api:jar' is not specified in the seam-validation-api pom. It is specified in it's parent, and gradle probably has some problems figuring it out. The parent part of seam-validation-api pom looks like this:
<parent>
<groupId>org.jboss.seam.validation</groupId>
<artifactId>seam-validation-parent</artifactId>
<version>3.1.0.Final</version>
<relativePath>../pom.xml</relativePath>
</parent>
<dependencies>
<dependency>
<groupId>javax.enterprise</groupId>
<artifactId>cdi-api</artifactId>
<scope>provided</scope>
</dependency>
</dependencies>
My gut feeling tells me the problem is in part. I also tried to add this parent dependency explicitely, by adding new line to build.gradle 'dependencies', but without any luck.
Anyone knows solution to this?
UPDATE: In the parent pom:
<groupId>org.jboss.seam.validation</groupId>
<artifactId>seam-validation-parent</artifactId>
<packaging>pom</packaging>
<version>3.1.0.Final</version>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.jboss.seam</groupId>
<artifactId>seam-bom</artifactId>
<version>${seam.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>

Here is a little research of the problem (only research, NOT a solution):
seam-validation-api-3.1.0.Final.pom has parent seam-validation-parent-3.1.0.Final.pom
seam-validation-parent-3.1.0.Final.pom has parent seam-parent-19.pom
The file seam-parent-4.pom contained version definition for cdi-api, but seam-parent-19.pom does not.
The file seam-validation-parent-3.0.0.Final.pom did contain dependencyManagement for cdi-api, but newer version seam-validation-parent-3.1.0.Final.pom does not.
I also looked into the code of GradlePomModuleDescriptorBuilder (the class that throws the abovementioned "Could not resolve..." exception). It seems that the class looks for DependencyManagement sections up the parent-pom chain, but it does not respect resolutionStrategy (or any other definitions from gradle script). So currently it is not possible to augment/override dependencyManagement of POM.
My advice: contact the developer(s) of seam framework and ask them to fix the dependencies.

Related

Parent POM's managed version not respecting version

I have a parent pom with a managed dependency that looks like
<dependency>
<groupId>edu.psu.cpr</groupId>
<artifactId>data-quality-services</artifactId>
<version>1.0.7</version>
</dependency>
I have a submodule with that uses that dependency. The pom entry looks like
<dependency>
<groupId>edu.psu.cpr</groupId>
<artifactId>data-quality-services</artifactId>
</dependency>
However the compile failed. When I looked at the effective pom for the submodule the entry looked like
<dependency>
<groupId>edu.psu.cpr</groupId>
<artifactId>data-quality-services</artifactId>
<version>1.0.6</version>
</dependency>
I've looked for something transitive but this is a top level dependency and is only coming in from a single place.
I ran mvn dependency:analyze-dep-mgt but it reported no issues.
Any and all suggestions will be greatly appreciated.
A colleague had done a merge which changed the artifactId in the parent pom. This resulted in the unexpected state.

Maven: using a dependency version as a property across different modules

I have got a project with a number of modules in it, now, e.g. I have a module M1 and its version 1.0.0 and in the same project I have got 8 other modules in which I have M1 as a dependency.
The problem is when I make a change in M1, update version to 1.0.1 and upload it to central repo, I have to change that version number 8 times.
I want to use this version number as property, which I have tried to put it as as a prop in parent pom but a maven warning saying its not right to do...
any thoughts? thanks in advance
Don't define the version as a property.
Adjust the <dependencyManagement> section in the parent pom like below:
<dependencyManagement>
<dependencies>
<dependency>
<groupId>com.yourGroup</groupId>
<artifactId>M1</artifactId>
<version>1.0.1</version>
</dependency>
<!-- eventually more dependencies -->
</dependencies>
</dependencyManagement>
In the 8 modules which depend on M1, insert:
<dependency>
<groupId>com.yourGroup</groupId>
<artifactId>M1</artifactId>
</dependency>
Take a look at the POM Reference - Dependency Management for further knowledge

Set Maven dependency versions in properties file

We have a couple of different applications which may or may not interact together. When they interact together, there have been issues because of mismatch in third party library versions (Let it be Spring or something else).
The pom files for these applications are separate, but to solve the above issue, we want them to use the same versions of third party libraries. The easiest way to do this is to specify the versions in common properties file, and then let respective pom.xml read the versions from the properties file.
Usually I am used to specify the versions as properties in the parent pom, and let the module pom read it from there. Is there a way I can make pom.xml read the properties file for reading the versions?
Some projects, e.g. spring-cloud and spring-boot, express their 'release train' (a set of dependencies and their versions that are known to work well together) in a 'BOM' (bill of materials). The BOM is nothing but a POM with only a dependencyManagement section, where all these dependencies are listed with the correct version. That BOM is then included in each project's POM that should follow these dependencies/versions in its dependencyManagement section, with scope 'import'.
E.g.
You create your separate project 'my-bom', containing only a pom like this:
<project>
<groupId>your.organication.program</groupId>
<artifactId>my-bom</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>pom</packaging>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.whatever</groupId>
<artifactId>somedependency</artifactId>
<version>1.2.3</version>
</dependency>
<dependency>
<groupId>com.whatever</groupId>
<artifactId>someotherdependency</artifactId>
<version>4.5.6</version>
</dependency>
</dependencies>
</dependencyManagement>
</project>
And then you include that in each project that should be aligned with these dependencies/versions:
groupId>your.organication.program.project</groupId>
<artifactId>some-project</artifactId>
<version>0.0.1-SNAPSHOT</version>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>your.organisation.program</groupId>
<artifactId>my-bom</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>
</dependencyManagement>
Within the projects the dependencies that are effectively used must still be referenced in dependencies-section, but without the version - the versions are managed by the BOM.

locking snapshot versions when depending on multi-module project

I have a multi-module project (B) that depends on various modules of another multi-module project (A). Each module of (B) might depend on different parts of (A), but they should all use the same version of (A). Current that version is specified as a property in the parent pom of (B).
I would like be able to lock the version used to a specific build (x.y.z-ts-buildnum) from a single command while keeping the version of (B) to use listed only once.
In parent:
<dep.version>4.1.0-SNAPSHOT</dep.version>
In a module:
<dependency>
<groupId>com.example</groupId>
<artifactId>B-foo</artifactId>
<version>${dep.version}</version>
</dependency>
I tried:
versions:lock-snapshots but that does not seem to lock versions set by properties
versions:update-properties which is for updating property versions but not locking snapshots
Writing a script around resolving the latests snapshot of A's pom from the local repository, but that does not work because each module has it's own timestamp. I could write a script to look at every module, but that's getting close to the amount of work a maven plugin would do.
I would suggest to define the dependencies to your module-A in your parent of the module-b like this:
<properties>
<module-a.version>6.5.0-12-SNAPSHOT</module-b.version>
</properties>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>com.example</groupId>
<artifactId>A-foo</artifactId>
<version>${module-a.version}</version>
</dependency>
<dependency>
<groupId>com.example</groupId>
<artifactId>A-bar</artifactId>
<version>${module-a.version}</version>
</dependency>
...
</dependencies>
</dependencyManagement>
Within your modules you now only need to write:
<dependency>
<groupId>com.example</groupId>
<artifactId>A-bar</artifactId>
</dependency>
which will give you the possibility to change the version of all modules only within a single place. At the root of your module-A.

Adding POM type dependency using m2eclipse, unable to resolve

I am trying to add Hector dependencies to my POM. My IDE is Eclipse, and I am also using m2eclipse. Adding dependencies of JAR type is not a problem, but this dependency is of type POM. I have tried almost everything usual including cleaning, building, and using import scope but nothing seem to have helped. When I try to add import me.prettyprint.hector.api.Serializer;
I get the error "The import cannot be resolved".
Is there anything else I need to do to use POM type dependencies or is there a better way of using dependencies of POM types in the project?
I believe his question is not as obvious as simply including the necessary dependency. I have experienced this problem too and am looking for a solution. The problem can be clearer stated as the following:
Let's say I have two maven projects (project A and project B). Project A is a simple web-app which wants to include dependencies as stated in project B. However, project B packaging type is "pom". This should allow all of project B's dependencies to be included into project A. Here is an example:
Project A (packaging is "war"):
<dependencies>
<dependency>
<groupId>com.foo</groupId>
<artifactId>B</artifactId>
<version>1.0</version>
<type>pom</type>
</dependency>
</dependencies>
Project B (packaging is "pom")
<dependencies>
<dependency>
<groupId>commons-lang</groupId>
<artifactId>commons-lang</artifactId>
<version>2.4</version>
</dependency>
</dependencies>
What we'd like to see in Eclipse is when you run maven eclipse:eclipse on Project A, that you can see the commons-lang-2.4.jar file as a dependency under project A such that you can resolve it in your code when imported. This is not happening and I'm still looking for such a solution.
The error indicates that the relevant class is missing in your classpath. A search of this class indicates, it is available in hector-core
This discussion indicates how this dependency can be imported, viz. adding the following entry to your project pom (or choosing this appropriately in m2eclipse).
<dependency>
<groupId>me.prettyprint</groupId>
<artifactId>hector-core</artifactId>
<version>0.7.0-29</version>
</dependency>

Categories

Resources