In my project I have dependency on org.jboss.seam.validation:seam-validation-api:3.1.0.Final. It has dependency on javax.enterprise:cdi-api, but without version, so gradle fails to resolve it. It shouldn’t be a big deal, I can exclude javax.enterprise:cdi-api.
The problem is, even if excluded, gradle still tries to figure out version number, and fails the whole build.
Error message:
Could not resolve all dependencies for configuration ‘:compile’.
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
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’
Thanks, I can reproduce the issue. The exclude of the module doesn’t work at the moment as the version of the dependency cannot be resolving when parsing the POM (which happens earlier than the exclude). I think we will need to be less strict in this case (especially because the scope of “cdi-api” is “provided”).
I think it’s debatable. On the one hand the version cannot be resolved which means that the dependency would generally not be resolvable. On the other hand the POM at least is treated gracefully when resolving it through Maven. My guess is that Maven also has a look at the scope. If the scope is not “compile” or “runtime”, then it doesn’t care about the missing version.
I had a deeper look at this issue. In one of the POMs, seam-bom-3.1.0-Final.pom, that is part of the POM import chain, we see the following:
<dependencyManagement>
<dependencies>
<!--
import the individual Java EE 6 API spec versions
-->
<dependency>
<groupId>org.jboss.spec</groupId>
<artifactId>jboss-javaee-6.0</artifactId>
<version>${jboss.javaee.version}</version>
<scope>import</scope>
<type>pom</type>
</dependency>
<!--
make Java EE 6 API available as stack artifact
-->
<!--
yes, we really need this one too!
-->
<dependency>
<groupId>org.jboss.spec</groupId>
<artifactId>jboss-javaee-6.0</artifactId>
<version>${jboss.javaee.version}</version>
<scope>provided</scope>
<type>pom</type>
</dependency>
...
</dependencies>
</dependencyManagement>
The imported POM is declared with scope ‘import’, later is defined with scope ‘provided’. When we parse the POM and identify multiple dependencies with the same ‘groupId’, ‘artifactId’ and ‘version’ we pick the last. As the scope of the last definition is ‘provided’, we do not import the POM. That’s why the property and the relevant ‘dependencyManagement’ declaration cannot be resolved. I am not sure why the dependency was declared twice with different scopes.
Concerning your last sentence I’ll try to explain:
The two imports have different meanings: The dependency-statement with scope ‘import’ imports all the definitions for the dependencies listed in the project/dependencyManagement/dependencies tag. The other one with scope ‘provided’ adds all the dependencies from the project/dependencies, like minimal/recommended dependencies. So you can define all the dependencies with the versions in dependencyManagement but you have not to add all in every case.