Considering that Java 1.9 is now out for some time, i am still amazed how difficult it is to get a 1.9 project up and running with eclipse and buildship.
I now spend 2 days trying to get this flying and came very far but one issue is something i just get not off the ground:
- "Right click on JUnit test case and 'Run as...'". It always ends in a java.lang.module.FindException and i have to override the command line as described in Eclipse cannot find module even the module path is explicitly provided.
On top comes this whole "eclipse.classpath.file.whenMerged" stuff in the build.gradle file (my file see below).
Hence my question is two-fold:
- Have i missed something that makes the jigsaw support with Gradle and buildship more easy?
- What do I have to do to not patch the command line manually (as described in the link above)?
As I am currently evaluating the support of Eclipse/Gradle/Buildship for my team I need to have the second question fixed. Otherwise the developer in my team are going to get nuts. As such I am also contemplating to move away from Eclipse.
Side question: How good is the support in other IDE for modules and Gradle?
I am using
- Eclipse 2020-12 (4.18.0.v20201202-1800)
- Eclipse Plug-ins for Gradle 3.1.4.v20200326-1743
- Java 12
- Grade 6.7.1
Thank you
/*
* This file was generated by the Gradle 'init' task.
*
* This generated file contains a sample Java library project to get you started.
* For more details take a look at the 'Building Java & JVM projects' chapter in the Gradle
* User Manual available at https://docs.gradle.org/6.7.1/userguide/building_java_projects.html
*/
plugins {
// Apply the java-library plugin for API and implementation separation.
id 'java-library'
id 'eclipse'
id 'application'
}
sourceCompatibility = targetCompatibility = '1.12'
repositories {
// Use JCenter for resolving dependencies.
jcenter()
}
dependencies {
// Use JUnit test framework.
testImplementation 'junit:junit:4.13'
// This dependency is used internally, and not exposed to consumers on their own compile classpath.
implementation 'org.postgresql:postgresql:42.2.18'
}
java {
modularity.inferModulePath = true
}
application {
mainModule = 'com.myproduct.mod.lib' // name defined in module-info.java
mainClass = 'com.myproduct.mod.lib.Library'
}
eclipse {
classpath {
file {
whenMerged {
//Define a module as being either a library or a project dependency.
//Test sources are excluded because eclipse wants them on the classpath for some reason (1)
entries.findAll { (it instanceof org.gradle.plugins.ide.eclipse.model.Library || it instanceof org.gradle.plugins.ide.eclipse.model.ProjectDependency) && !it.entryAttributes.get('gradle_used_by_scope').equals('test') }.each {
it.entryAttributes['module'] = 'true'
}
//Test-scoped stuff should set the appropriate flag
entries.findAll { (it.properties.kind.equals('src') || it.properties.kind.equals('lib')) && it.entryAttributes.get('gradle_used_by_scope').equals('test') }.each {
it.entryAttributes['test'] = 'true'
}
entries.findAll { isConGradle(it) }.each {
it.entryAttributes['module'] = 'true'
}
}
}
}
}
boolean isConGradle(entry) {
entry.kind == 'con' && entry.path == 'org.eclipse.buildship.core.gradleclasspathcontainer'
}