Custom plugin with native jar dependency

Hello,

I’m making a custom Gradle plugin that uses some native dependencies. The task works well when used inside a buildSrc directory, but not when published.

I dig a bit, and it appears that the pom.xml generated by the ‘com.gradle.plugin-publish’ omit some dependencies. Here the dependencies (build.gradle):

dependencies {
	implementation "org.lwjgl:lwjgl:3.2.3"
	implementation "org.lwjgl:lwjgl-shaderc:3.2.3"
	runtimeOnly "org.lwjgl:lwjgl:3.2.3:natives-linux"
	runtimeOnly "org.lwjgl:lwjgl-shaderc:3.2.3:natives-linux"
}

And the generated pom.xml (build/publish-generated-resources/pom.xml):

    <?xml version="1.0" encoding="UTF-8" standalone="no"?>
    <project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 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">
      <modelVersion>4.0.0</modelVersion>
      <groupId>gradle.plugin.org.isotropy.gradleshaderc</groupId>
      <artifactId>buildSrc</artifactId>
      <version>0.0.3</version>
      <dependencies>
        <dependency>
          <groupId>org.lwjgl</groupId>
          <artifactId>lwjgl</artifactId>
          <version>3.2.3</version>
          <scope>runtime</scope>
          <type>jar</type>
          <optional>false</optional>
        </dependency>
        <dependency>
          <groupId>org.lwjgl</groupId>
          <artifactId>lwjgl-shaderc</artifactId>
          <version>3.2.3</version>
          <scope>runtime</scope>
          <type>jar</type>
          <optional>false</optional>
        </dependency>
      </dependencies>
    </project>

I expected two more dependencies in the pom.xml, something like:

<dependency>
	<groupId>org.lwjgl</groupId>
	<artifactId>lwjgl</artifactId>
	<classifier>natives-linux</classifier>
</dependency>
<dependency>
	<groupId>org.lwjgl</groupId>
	<artifactId>lwjgl-shaderc</artifactId>
	<classifier>natives-linux</classifier>
</dependency>

Maybe there is something more to do for this use case?
Or at worse: how could I customize how the pom.xml is generated before the publish?

Hi @Ealrann

I posted an answer on the bug you reported: https://github.com/gradle/gradle/issues/11958#issuecomment-577897713

I hope this works for you!

1 Like