How should gradle handle "hk2-jar" dependencies?

I’m facing a dependency problem where gradle tries to fetch a hk2-jar from the repo which can not be found there. It’s the dependency runtime 'org.glassfish.ha:ha-api:3.1.9' which is problematic.

Other projects are having similar issues with this library (see https://issues.apache.org/jira/browse/IVY-1357 and https://groups.google.com/forum/#!topic/simple-build-tool/AYLw15EJcvg ).

What is the “gradle way” of handling such situations?

UPDATE: In the meantime I solved my original problem by changing the dependency line to runtime 'org.glassfish.ha:ha-api:3.1.9@jar' but I think a general statement could be helpful for others.

UPDATE2: Unfortunetaly the workaround solution above only works for projects that are not used as dependencies by other projects.

It looks like there’s a problem with the pom at http://central.maven.org/maven2/org/glassfish/ha/ha-api/3.1.8/ha-api-3.1.8.pom

<groupId>org.glassfish.ha</groupId>
<artifactId>ha-api</artifactId>
<version>3.1.8</version>
<packaging>hk2-jar</packaging>

But the artifact has a jar extension (not hk2-jar)

You might be able to solve this with a dependency substitution

configurations.all {
   resolutionStrategy.dependencySubstitution {
      all { DependencySubstitution dependency ->
        def requested = dependency.requested
        if (requested instanceof ModuleComponentSelector && requested.group == 'org.glassfish.ha' && requested.name == 'ha-api') {
          dependency.useTarget "org.glassfish.ha:ha-ap:${requested.version}@jar"
        }
      }
   }
}

But this substitution would have to be included in every project that has my project as dependency? The problem is not my own project but the other projects that have a dependency on my project and get this ha-api as transitive dependency with the wrong externsion.

I would’ve hoped that gradle would explicitly state <type>jar</type> in the published pom for this dependency since it was explicit in the dependency substitution. If not, you may need to hack the published pom xml for the dependency.

publications {
    foo(MavenPublication) {
        pom.withXml {
           def dependency = asNode().dependencies.dependency.find {
              it.groupId.text() == 'org.glassfish.ha' && it.artifactId.text() == 'ha-api')
           }
           dependency.appendNode('type', 'jar')       
        } 
    }
}