Eclipse plugin multi project .classpath contains to much

eclipse
plugins

(Klaus Christiansen) #1

I see some strange behavior with the .classpath file.

Gradle 3.3, Java8, Windows 10

I have a multi project build. I use the Java and Eclipse plugins.

Project FOO depends on project BAR and some junit.jar
BAR depends on postgresql.jar

gradle eclipse creates the .classpath file. But it contains more then it needs for project FOO. postgresql.jar should not be in FOO/.classpath

Foo/build.gradle

apply plugin: 'java'
apply plugin: 'eclipse'
 
repositories {
    mavenCentral()
}
 
sourceSets {
    main.java.srcDirs = ['src']
    test.java.srcDirs = ['test']
}
 
dependencies {
    compile project(':BAR') 

    testCompile("junit:junit:4.12")
}
 
eclipse {
    pathVariables 'GRADLE_USER_HOME': gradle.gradleUserHomeDir
}

BAR/build.gradle

apply plugin: 'java'
apply plugin: 'eclipse'
 
repositories {
    mavenCentral()
}
 
sourceSets {
    main.java.srcDirs = ['src']
    test.java.srcDirs = ['test']
}
 
dependencies {
    compile 'org.postgresql:postgresql:9.+'
}
 
eclipse {
    pathVariables 'GRADLE_USER_HOME': gradle.gradleUserHomeDir
}

FOO/.classpath

<?xml version="1.0" encoding="UTF-8"?>
<classpath>
	<classpathentry kind="src" path="src"/>
	<classpathentry path="bin" kind="output"/>
	<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8/"/>
	<classpathentry kind="src" path="/BAR"/>
	<classpathentry sourcepath="GRADLE_USER_HOME/caches/modules-2/files-2.1/junit/junit/4.12/a6c32b40bf3d76eca54e3c601e5d1470c86fcdfa/junit-4.12-sources.jar" kind="var" path="GRADLE_USER_HOME/caches/modules-2/files-2.1/junit/junit/4.12/2973d150c0dc1fefe998f834810d68f278ea58ec/junit-4.12.jar"/>
	<classpathentry sourcepath="GRADLE_USER_HOME/caches/modules-2/files-2.1/org.postgresql/postgresql/9.4.1212/d007dc0d6b3470582929bae1346c0659a4d448eb/postgresql-9.4.1212-sources.jar" kind="var" path="GRADLE_USER_HOME/caches/modules-2/files-2.1/org.postgresql/postgresql/9.4.1212/38931d70811d9bfcecf9c06f7222973c038a12de/postgresql-9.4.1212.jar"/>
	<classpathentry sourcepath="GRADLE_USER_HOME/caches/modules-2/files-2.1/org.hamcrest/hamcrest-core/1.3/1dc37250fbc78e23a65a67fbbaf71d2e9cbc3c0b/hamcrest-core-1.3-sources.jar" kind="var" path="GRADLE_USER_HOME/caches/modules-2/files-2.1/org.hamcrest/hamcrest-core/1.3/42a25dc3219429f0e5d060061f71acb49bf010a0/hamcrest-core-1.3.jar"/>
</classpath>

The second classpath entry (postgresql) has no reason to be here.
How do I keep subprojects dependencies out of the top project’s .classpath file?


(Stefan Oehme) #2

Foo depends on bar and bar declares a compile dependency on postgres. This means that foo also needs postgres to run.

We don’t use Eclipse’s reexport feature as it completely breaks conflict resolution. Instead each eclipse project declares everything it needs in a flat classpath.