Skip to content

Commit

Permalink
Add module descriptor while maintaining Eclipse IDE experience
Browse files Browse the repository at this point in the history
* Fixes ben-manes#535
* Uses Gradle Eclipse plugin to define add-reads options which
  satisfy Eclipse and make the project buildable through it in
  Eclipse 2021-03

Only the core caffeine module was eligible for a full module
  descriptor considering the circumstances:
* A descriptor was not added to caffeine-guava because some of
  its tests rely on split packages in order to acccess Guava's
  package-private types. Ensuring a smooth experience in
  Eclipse IDE requires resolving these split packages.
* The other modules still have some dependencies on filename-based
  modules, so it would be unwise to add module descriptors for
  them.
  • Loading branch information
A248 committed Apr 24, 2021
1 parent ba78559 commit e734b7c
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 5 deletions.
21 changes: 19 additions & 2 deletions caffeine/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,21 @@ idea.module {
scopes.PROVIDED.plus += [ configurations.javaPoetCompileClasspath ]
}

eclipse.classpath.file.whenMerged {
entries.findAll { it instanceof SourceFolder && it.output == 'bin/codeGen' }*.output = 'bin/main'
eclipse.classpath {
containers 'org.eclipse.buildship.core.gradleclasspathcontainer'
file {
whenMerged {
entries.findAll { it instanceof SourceFolder && it.output == 'bin/codeGen' }*.output = 'bin/main'
entries.findAll { it instanceof org.gradle.plugins.ide.eclipse.model.AbstractClasspathEntry }.each {
it.entryAttributes['module'] = 'true'
}
def modules = [ 'java.compiler', 'java.logging', 'jdk.unsupported', 'com.google.common',
'com.google.googlejavaformat', 'guava.testlib', 'it.unimi.dsi.fastutil', 'org.apache.commons.lang3',
'org.cache2k.api', 'org.hamcrest', 'org.jctools.core', 'org.mockito', 'org.testng' ]
def main = entries.find { it instanceof SourceFolder && it.path == 'src/main/java' }
main.entryAttributes['add-reads'] = buildAddReads('com.github.benmanes.caffeine', modules)
}
}
}

plugins.withType(EclipsePlugin) {
Expand Down Expand Up @@ -66,6 +79,10 @@ dependencies {
javaPoetImplementation libraries.googleJavaFormat
}

compileJava {
modularity.inferModulePath = true
}

compileCodeGenJava {
gradle.taskGraph.whenReady {
enabled = gradle.taskGraph.hasTask('uploadArchives')
Expand Down
8 changes: 8 additions & 0 deletions caffeine/src/main/java/module-info.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@

module com.github.benmanes.caffeine {
exports com.github.benmanes.caffeine.cache;
exports com.github.benmanes.caffeine.cache.stats;

requires static transitive org.checkerframework.checker.qual;
requires static transitive com.google.errorprone.annotations;
}
10 changes: 7 additions & 3 deletions gradle/dependencies.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ ext {
elasticSearch: '7.12.0',
expiringMap: '0.5.9',
fastfilter: '1.0',
fastutil: '8.5.4',
fastutil: '8.5.2',
flipTables: '1.1.0',
googleJavaFormat: '1.10.0',
guava: '30.1.1-jre',
Expand Down Expand Up @@ -165,10 +165,14 @@ ext {
jcacheTck: "javax.cache:cache-tests:${testVersions.jcacheTck}",
jcacheTckTests: "javax.cache:cache-tests:${testVersions.jcacheTck}:tests",
jctools: "org.jctools:jctools-core:${testVersions.jctools}",
junit: "junit:junit:${testVersions.junit}",
junit: dependencies.create("junit:junit:${testVersions.junit}") {
exclude group: 'org.hamcrest'
},
mockito: "org.mockito:mockito-core:${testVersions.mockito}",
osgiCompile: [
"org.ops4j.pax.exam:pax-exam-junit4:${testVersions.paxExam}",
dependencies.create("org.ops4j.pax.exam:pax-exam-junit4:${testVersions.paxExam}") {
exclude group: 'org.hamcrest'
},
],
osgiRuntime: [
"org.apache.felix:org.apache.felix.framework:${testVersions.felix}",
Expand Down
13 changes: 13 additions & 0 deletions gradle/eclipse.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -48,3 +48,16 @@ def ignoreDerivedResources(projectDescription, directories = [
}
}
}

ext.buildAddReads = { subjectModule, addModules ->
def addReads = new StringBuilder()
addModules.each {
if (addReads.length() != 0) {
addReads.append(':')
}
addReads.append(subjectModule)
addReads.append('=')
addReads.append(it)
}
return addReads.toString()
}

0 comments on commit e734b7c

Please sign in to comment.