Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dependency transitive issue in coding phase and running phase #1657

Closed
Vanco opened this issue Jun 15, 2024 · 7 comments
Closed

dependency transitive issue in coding phase and running phase #1657

Vanco opened this issue Jun 15, 2024 · 7 comments
Assignees
Labels
Milestone

Comments

@Vanco
Copy link

Vanco commented Jun 15, 2024

What happened?

I have a multi-module plugin project where one plugin project depends on the other.
Let's simplify the scenario:

muti-plugin is the root gradle project. it has two subproject, plugin-base and plugin-ext. the project plugin-base export some extention point, and when published, it contain four jars in the final zip.

    └── plugin-base
        └── lib
             │   batik-all-1.17.jar
             │   plugin-base-1.0-SNAPSHOT-instrumented.jar
             │   xml-apis-ext-1.3.04.jar
             │   xmlgraphics-commons-2.9.jar

the project plugin-ext depends on plugin-base, and make use the extention point, when published, it contain one jar in the final zip.

plugin-ext
        └── lib
            │   plugin-ext-1.0-SNAPSHOT-instrumented.jar
configuration in build.gradle.kts

plugin-base/build.gradle.kts

plugins {
    id("java")
    id("org.jetbrains.kotlin.jvm") version "1.9.23"
    id("org.jetbrains.intellij.platform") version "2.0.0-beta7"
}

group = "vanstudio"
version = "1.0-SNAPSHOT"

repositories {
    maven("https://maven.aliyun.com/repository/public")
    maven("https://maven.aliyun.com/repository/gradle-plugin")
    mavenCentral()
    intellijPlatform {
        defaultRepositories()
    }
}

dependencies {
    implementation("org.apache.xmlgraphics:batik-all:1.17") {
        exclude("xml-apis")
        exclude("commons-io")
        exclude("commons-logging")
    }
    implementation("xml-apis:xml-apis-ext:1.3.04")
    intellijPlatform {
        intellijIdeaCommunity("2024.1.1")
        bundledPlugins("com.intellij.java")
        instrumentationTools()
    }
}

intellijPlatform {
    buildSearchableOptions = false
    sandboxContainer = File(providers.environmentVariable("HOME").get() + "/.sandbox")
}

plugin-ext/build.gradle.kts

plugins {
    id("java")
    id("org.jetbrains.kotlin.jvm") version "1.9.23"
    id("org.jetbrains.intellij.platform") version "2.0.0-beta7"
}

group = "vanstudio"
version = "1.0-SNAPSHOT"

repositories {
    maven("https://maven.aliyun.com/repository/public")
    maven("https://maven.aliyun.com/repository/gradle-plugin")
    mavenCentral()
    intellijPlatform {
        defaultRepositories()
        localPlatformArtifacts()
    }
}

dependencies {
    intellijPlatform {
        intellijIdeaCommunity("2024.1.1")
        bundledPlugins("com.intellij.java")
        localPlugin(project(":plugin-base"))
        instrumentationTools()
    }
}

intellijPlatform {
    buildSearchableOptions = false
    sandboxContainer = File(providers.environmentVariable("HOME").get() + "/.sandbox")
}

issue one: dependency transitive lost in coding phase

In the coding phase, the jars batik-all-1.17.jar, xml-apis-ext-1.3.04.jar, xmlgraphics-commons-2.9.jar should be visible in project plugin-ext, but in the version from 2.0.0-beta3 to 2.0.0-bata7, the transitive dependencies jars are lost.

issue two: dependent plugin plugin-base has wrong structure when unzip into sandbox in running phase

When run project plugin-ext by command gradle :plugin-ext:runIde, there should have both plugin plugin-base and plugin plugin-ext deployed into sandbox in correct structure like:

.IntelliJIDEAx0/
└── plugins
    └── plugin-base
        └── lib
             │   batik-all-1.17.jar
             │   plugin-base-1.0-SNAPSHOT-instrumented.jar
             │   xml-apis-ext-1.3.04.jar
             │   xmlgraphics-commons-2.9.jar
    └── plugin-ext
        └── lib
            │   plugin-ext-1.0-SNAPSHOT-instrumented.jar

but in the version from 2.0.0-beta3 to 2.0.0-bata7, the plugin-base deployed in wrong structure, by put four jars direct under plugins directory:

.IntelliJIDEAx0/
└── plugins
             │   batik-all-1.17.jar
             │   plugin-base-1.0-SNAPSHOT-instrumented.jar
             │   xml-apis-ext-1.3.04.jar
             │   xmlgraphics-commons-2.9.jar

in this way, the jars batik-all-1.17.jar, xml-apis-ext-1.3.04.jar, xmlgraphics-commons-2.9.jar are trade as single jar idea plugin, but it is not. and the plugin-base-1.0-SNAPSHOT-instrumented.jar has plugin.xml in it, looks like a single jar idea plugin, but it missing dependent jars. this is totally wrong.

Relevant log output or stack trace

No response

Steps to reproduce

I attached the muti-plugin demo project code for demonstrate both of thease bugs.
muti-plugin.zip

Gradle IntelliJ Plugin version

2.0.0-beta7

Gradle version

8.6

Operating System

None

Link to build, i.e. failing GitHub Action job

No response

@Vanco Vanco added the bug label Jun 15, 2024
@YannCebron YannCebron added this to the 2.0 milestone Jul 4, 2024
@hsz
Copy link
Member

hsz commented Jul 12, 2024

@Vanco thank you for a brilliant description and reproducible project.
Could you please verify if everything is now satisfied on your side with 2.0.0-beta9?

@Vanco
Copy link
Author

Vanco commented Jul 15, 2024

Ok, Thanks. I will test and verify it today.

@Vanco
Copy link
Author

Vanco commented Jul 15, 2024

I test.

issue one: dependency transitive lost in coding phase

In the coding phase, the jars batik-all-1.17.jar, xml-apis-ext-1.3.04.jar, xmlgraphics-commons-2.9.jar should be visible in project plugin-ext, but in the version from 2.0.0-beta3 to 2.0.0-bata7, the transitive dependencies jars are lost.

Issue one is not fixed.

Let me explain it:
In my demo code DemoExt, I write the line

DOMImplementation impl = SVGDOMImplementation.getDOMImplementation();

here I referenced SVGDOMImplementation, which come from batik-all-1.17.jar. I'd expect to be able to reference this class via the Jar package dependency transitive:

flowchart LR
A["plugin-ext"]
B["plugin-base"]
C["batik-all-1.17.jar"]
A --depend on--> B --depend on--> C
Loading

but I get reference unresolved error, and asked me to adds library "batik.all" to the dependencies of module "Muti-plugin.plugin-ext.main" and imports unresolved "SVGDOMImplementation".
error-tip

If I add batik-all-1.17.jar directly to module plugin-ext, that means the dependency transitive of localPlugin(project(":plugin-base")) was fail.

the dependency transitive is the behavior I expect on localPlugin(project(":plugin-base")) in coding phase.

@Vanco
Copy link
Author

Vanco commented Jul 15, 2024

BTW, the issue two was fixed.

1 similar comment
@Vanco
Copy link
Author

Vanco commented Jul 15, 2024

BTW, the issue two was fixed.

@hsz
Copy link
Member

hsz commented Jul 15, 2024

Thank you for the further explanations!
Apparently, we're facing problem with how Gradle works here. I have investigated dependencies resolutions and the fact that i.e. batik library is not present in the plugin-ext classpath and it seems working correctly:

  1. When you declare a dependency on a plugin-base module with:
dependencies {
    intellijPlatform {
        localPlugin(project(":plugin-base"))
    }
}

it loads the base module correctly, but without its transitive dependencies — this is because plugin-base uses implementation("org.apache.xmlgraphics:batik-all:1.17") — and those aren't propagated further.

compileClasspath - Compile classpath for null/main.
...
+--- idea:ideaIC:2024.1.1
\--- project :plugin-base
  1. If you do the same, but make plugin-base use api() instead of implementation() for dependencies you expect to share with plugin-extbatik becomes available:
compileClasspath - Compile classpath for null/main.
...
+--- idea:ideaIC:2024.1.1
\--- project :plugin-base
     +--- org.apache.xmlgraphics:batik-all:1.17
     |    \--- org.apache.xmlgraphics:xmlgraphics-commons:2.9
     \--- xml-apis:xml-apis-ext:1.3.04

All this happens when you declare a dependency on a project(...).

  1. If you point to the actual plugin-base ZIP distribution file, it extracts this archive and loads all bundled Jar files.
compileClasspath - Compile classpath for null/main.
...
+--- idea:ideaIC:2024.1.1
\--- localPlugin:vanstudio.plugin-base:1.0-SNAPSHOT+770

And this depenendy points to its bundled artifacts:
image

@Vanco
Copy link
Author

Vanco commented Jul 16, 2024

Oh, I see. In the case of my current project, I just changed the implementation() to api() and that was what I was looking for. Thank you for the explanation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants