buildship
buildship copied to clipboard
The runtime scope is not taken into account and all dependencies of pom included in eclipse compile classpath
Runtime dependencies are shown in gray in "Project and External Dependencies" in package explorer, that's how I can see they are in the runtime classpath of eclipse and not in the compile classpath. Scope "test" dependencies are also shown in gray and compile dependencies are shown in white.
Expected Behavior
When I add a gradle dependency to my project as 'implementation', I expect buildship to read the whole pom and make the difference between scope runtime and default which is compile. It should appear with the right color code (gray for runtime or maybe some other color to distinguish from test). It's not just a matter of display, the color is just a hint for me to know that the library was included in the runtime classpath, not in the compile classpath.
Current Behavior
All dependencies of the pom are recursively included in the compile classpath (white color in "Project and External Dependencies" in package explorer).
Context
I'm trying to use a library org-netbeans-modules-diff that has some features that I need for a project and one of its runtime dependencies org-netbeans-bootstrap must absolutely not be included in the compile classpath, otherwise it makes the build crash. It is because org-netbeans-bootstrap repackages java/lang/Module but it doesn't matter at runtime. It started with this bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=578279.
Steps to Reproduce
Create 2 projects:
- 1 gradle project with build.gradle:
plugins {
id 'java'
}
repositories {
mavenCentral()
}
dependencies {
implementation 'org.netbeans.api:org-netbeans-modules-options-api:RELEASE126'
}
Right click "Gradle -> Refresh Gradle Project" and look at the "Project and External Dependencies" in the package explorer => all white / compile
- 1 maven project with pom.xml:
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.mycompany.myproject</groupId>
<artifactId>test-maven</artifactId>
<version>0.0.1-SNAPSHOT</version>
<dependencies>
<dependency>
<groupId>org.netbeans.api</groupId>
<artifactId>org-netbeans-modules-options-api</artifactId>
<version>RELEASE126</version>
</dependency>
</dependencies>
</project>
Right-click "Maven -> Update Maven Project" and look at "Maven Dependencies" in the package explorer => you should be able to see the runtime dependencies in gray
Your Environment
Eclipse Version: 2021-12 (4.22.0) Build id: 20211202-1639
Gradle 7.3.3 Maven 3.8.1
Can you please paste .classpath file content here from the maven project? I'm curious how the "grey" dependencies are defined. By default, the grey icon is used for dependencies that are visible for test sources only.
Not sure this helps. Dependencies used to be expanded in .classpath
but that's no longer the case :
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-17">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="src" output="target/classes" path="src/main/java">
<attributes>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="src" output="target/test-classes" path="src/test/java">
<attributes>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
<attribute name="test" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="output" path="target/classes"/>
</classpath>
You are right, it's not particularly helpful. m2e pulls the same trick as Buildship: they both contribute a classpath container where the dependencies are listed.
<attribute name="test" value="true"/>
This tells Eclipse the source folder is test source code. Similarly an IClasspathEntry
for a test scoped item should have an IClasspathAttribute
of test
=true
. This will tell Eclipse the classpath entry is not for source compilation (source folders without test
=true
attribute).
What needs to be done was previously requested by https://github.com/eclipse/buildship/issues/689. The resolution to that issue only seems to have added test
=true
to the .classpath file and not to the IClasspathEntry in the container.