Eclipse Plugin - Exclude JRE_CONTAINER entry from .classpath generation

eclipse

(Paolo Finamore) #1

Hi Everyone,

I have an eclipse installation with several JREs installed (1.5,1.6 and 1.8). The selected one in the workspace preferences is the 1.8. (This mean that when an eclipse project is created, JRE 1.8 is used by default).
I have a project in the workspace with the JRE 1.6 in the build path.

I tried to add the log4j dependency using the eclipseClasspath task of the eclipse plugin.

After the task execution the .classpath file contains two JRE_CONTAINER entry (1.6 and 1.8).
I think that eclipseClasspath task get the default Eclipse JRE variable (1.8 in this case) and add it in the classpath.

I wouldn’t add the JRE 1.8 in the classpath, i would add just the log4j dependencies (JRE 1.6 is already in the classpath).
Is it possible to configure the eclipseClasspath task to exclude the JRE_CONTAINER from .classpath generation?

NOTE 1: I’m looking for a clean solution, i wouldn’t loop the classpath entries and remove the duplicated JRE_CONTAINER entry.

NOTE 2: I’ve already seen this topic. I don’t want clean my classpath file

Below my build script

apply plugin: 'java'
apply plugin: 'eclipse'

group = 'it.ipzs.ws'
version = '0.2'
targetCompatibility = 1.5
jar {
    manifest {
        attributes 'Implementation-Title': 'soaputil-ws',
                   'Implementation-Version': version,
                   'Main-Class': 'it.ipzs.ws.util.SOAPUtil'
    }
}

repositories {
    jcenter()
    mavenLocal()
}

//eclipse plugin configuration
configurations {
    provided
}

dependencies {
    compile 'log4j:log4j:1.2.16'
}

sourceSets {
  main {
    
    java {
      srcDir 'src'
    }
    
    resources {
      srcDir 'resources'
    }
    
  }
}
compileJava{
    targetCompatibility = 1.5
}

(Stefan Oehme) #2

What version of Gradle are you using? Recent versions of Gradle configure the correct JRE container based on your targetCompatiblilty.


(Paolo Finamore) #3

I’m using Gradle 2.5


(Stefan Oehme) #4

Please upgrade to a recent version of Gradle. The current is 2.13 and 2.14 is around the corner.


(Paolo Finamore) #5

I have installed version 2.13 and, as you told me, the eclipseClasspath task update the JRE_CONTAINER with the jdk version specified by the targetCompatibility variable in the build script.

But it works only with version 1.6, 1.7 and 1.8 of java.

It doesn’t work with 1.4 and 1.5. Because the eclipseClasspath task add an entry in the .classpath named “JavaSE-1.5” and “JavaSE-1.4”.
Those JRE Environments doesn’t exists in my eclipse installation, because Java, up to 1.6 version, was named “J2SE”.
It should add “J2SE-1.5” or “J2SE-1.4”

I hereby attach a screenshot of Eclipse’s Execution Environments


(Stefan Oehme) #6

Compiling with Java 5 is deprecated in Gradle 2.x and will be removed in Gradle 3.0.


(Paolo Finamore) #7

Ok, thank you very much.