2

I have a package which is a JNI wrapper around native code and is therefore platform dependent. I want to create a platform specific jar using os-maven-plugin. The relevant part of my pom is as follows:

<groupId>foo.bar.baz</groupId>
<artifactId>project</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>


<build>
    <extensions>
        <extension>
            <groupId>kr.motd.maven</groupId>
            <artifactId>os-maven-plugin</artifactId>
            <version>1.6.1</version>
        </extension>
    </extensions>
    <plugins>
        <plugin>
           <artifactId>maven-jar-plugin</artifactId>
           <version>3.1.0</version>
           <configuration>
                <classifier>${os.detected.classifier}</classifier>
            </configuration>
        </plugin>
    </plugins>
    // ...

After running mvn clean install, it seems the artifact is built appropriately:

$ ls /Users/erip/.m2/repository/foo/bar/baz/project/0.0.1-SNAPSHOT
_remote.repositories                        project-0.0.1-SNAPSHOT-osx-x86_64.jar
maven-metadata-local.xml                    project-0.0.1-SNAPSHOT.pom

however, when I add this dependency to my gradle file…

repositories {
    // ...
    mavenLocal()
}

dependencies {
    // ...
    compile 'foo.bar.baz:project:0.0.1-SNAPSHOT:osx-x86_64' 
}

and try to build, gradle says it can’t find the file:

$ ./gradlew clean build
> Task :compileJava FAILED

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':compileJava'.
> Could not resolve all files for configuration ':compileClasspath'.
   > Could not find foo.bar.baz:project:0.0.1-SNAPSHOT.
     Searched in the following locations:
       ...
       - file:/Users/erip/.m2/repository/foo/bar/baz/project/0.0.1-SNAPSHOT/project-0.0.1-SNAPSHOT.pom
     Required by:
         project :

It looks in an existing pom, but fails to resolve the jar, so why can't gradle find this dependency?

erip
  • 16,374
  • 11
  • 66
  • 121

2 Answers2

2

Resolving dependencies with classifiers is currently not supported by Gradle as of 6.8 as corroborated by this issue.

erip
  • 16,374
  • 11
  • 66
  • 121
0

Re os-maven-plugin: The Java System Properties:

  • os.name
  • os.arch
  • os.version

are available in POMs. Aren't these enough for your artifact classifiers?

Re your not found dependency: The Gradle dependencies doc mentions classifiers just in conjunction with JavaScript. The examples for dependencies there use just <groupId>:<artifactId>:<version>. (Where did you get the 3-colon syntax with the additional :<classifier>?) The POM Reference mentions classifiers/qualifiers as part of the version, so I'd try:

dependencies {
    // ...
    compile 'foo.bar.baz:project:0.0.1-SNAPSHOT-osx-x86_64' 
}
Gerold Broser
  • 14,080
  • 5
  • 48
  • 107
  • According to [this test](https://github.com/gradle/gradle/blob/124712713a77a6813e112ae1b68f248deca6a816/subprojects/dependency-management/src/test/groovy/org/gradle/api/internal/notations/DependencyStringNotationConverterTest.groovy#L55-L74), short dependency notation should be OK - the dependency you listed will just point to an actually non-existent one. – erip Jan 11 '21 at 23:29
  • @erip I see. Apparently the Gradle doc is even worse than the Maven doc. :) – Gerold Broser Jan 11 '21 at 23:33
  • @erip The [`with artifact`](https://github.com/gradle/gradle/blob/124712713a77a6813e112ae1b68f248deca6a816/subprojects/dependency-management/src/test/groovy/org/gradle/api/internal/notations/DependencyStringNotationConverterTest.groovy#L34) test, OTOH, uses a classifier in the version part. Since these are unit tests I'm not sure whether the dependencies there really exist and are really resolved or whether there's just a (string) comparison with expected results. – Gerold Broser Jan 11 '21 at 23:50
  • I don't think it's a classifier in that test. I think it's just a normal part of a play on semantic versions. – erip Jan 12 '21 at 00:02
  • @erip I think, in terms of Maven it is a classifier: "_It is some optional and arbitrary string that - if present - is appended to the artifact name just after the version number._". Did you try the suggestion of my answer or are we just talking theoretically here? – Gerold Broser Jan 12 '21 at 00:12
  • Yes, I tried it. See [pastebin](https://pastebin.com/2GAtwMmi). – erip Jan 12 '21 at 00:56
  • @erip What if you [_not_ use short dependency notation](https://stackoverflow.com/q/13188438/1744774)? – Gerold Broser Jan 12 '21 at 01:34
  • 1
    Same error. I'm afraid it might just be a bug in Gradle. – erip Jan 12 '21 at 11:58
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/227200/discussion-between-erip-and-gerold-broser). – erip Jan 12 '21 at 12:14
  • 1
    I've opened [this bug](https://github.com/gradle/gradle/issues/15756) - we'll see how that goes. – erip Jan 12 '21 at 12:24