Classifier missing in generated pom.xml based on project dependencies

Hello fellows,

I commented in netmikey’s post [http://forums.gradle.org/gradle/topics/gradle_1_9_dependency_resolution_issue_if_artifact_present_in_multiple_scopes_within_the_pom] the other day about Maven dependencies in Gradle 1.9+ not working entirely satisfactory.

See the examples in the other post.

Having further investigated the problem from what I can see my issue boils down to the generated pom.xml not correctly containing the classifier when generating the pom.xml file based on project dependencies. When generating a pom any classifier specified as external module dependencies translates into the pom, for project dependencies it does not.

I dont think it ever has for project dependencies, but Gradle 1.8- made it work anyway. Now with the stricter/correct pom interpretation it does not work.

External dependencies block and pom.xml:

dependencies {
    compile 'deptest.B:B:1.0'
    testCompile 'deptest.B:B:1.0:test'
}
<?xml version="1.0" encoding="UTF-8"?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <modelVersion>4.0.0</modelVersion>
  <groupId>deptest.D</groupId>
  <artifactId>C</artifactId>
  <version>1.0</version>
  <dependencies>
    <dependency>
      <groupId>deptest.B</groupId>
      <artifactId>B</artifactId>
      <version>1.0</version>
      <scope>compile</scope>
    </dependency>
    <dependency>
      <groupId>deptest.B</groupId>
      <artifactId>B</artifactId>
      <version>1.0</version>
      <classifier>test</classifier>
      <scope>test</scope>
    </dependency>
  </dependencies>
</project>

Project dependencies block and pom.xml:

dependencies {
    compile project(":A")
    testCompile project(path: ":A", configuration: 'testRuntime')
}
<?xml version="1.0" encoding="UTF-8"?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <modelVersion>4.0.0</modelVersion>
  <groupId>deptest.B</groupId>
  <artifactId>B</artifactId>
  <version>1.0</version>
  <dependencies>
    <dependency>
      <groupId>deptest.A</groupId>
      <artifactId>A</artifactId>
      <version>1.0</version>
      <scope>compile</scope>
    </dependency>
    <dependency>
      <groupId>deptest.A</groupId>
      <artifactId>A</artifactId>
      <version>1.0</version>
      <scope>test</scope>
    </dependency>
  </dependencies>
</project>

No classifier on the test scope even though it is specified on the test-jar.

In the testRuntime configuration I have placed a test-artifact for test-dependencies used as above. The classifier linked to this artifact however does not translate into the pom which cause the latest entry in pom per artifact priority issue.

Thank you, Stefan

Hello,

Usually you are pretty fast to respond on a query with at least a yes/no/maybe.

If my report is unclear I can supply more examples.

When writing the pom.xml the classifier specified (if one is specified) on the artifact is not written into the pom through project dependencies. My test-dependency above become a classifier-less (normal) dependency on the test scope when it should also have had ‘test’ as classifier as specified on the jar-task.

Thanks, Stefan

It may be a limitation of the current implementation. Raised GRADLE-3030.

Great! Thank you Peter.

Stefan

Hi guys,

To speed this fix along I have attached a working code change to the jira that will fix the issue.

Have a look and feel free tidy things up if you see a cleaner solution.

Thanks, Stefan