From e734b7cdd7093e089fdfa915ae96bc7aa3ba1afe Mon Sep 17 00:00:00 2001 From: A248 Date: Sat, 17 Apr 2021 08:54:31 -0400 Subject: [PATCH] Add module descriptor while maintaining Eclipse IDE experience * Fixes #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. --- caffeine/build.gradle | 21 +++++++++++++++++++-- caffeine/src/main/java/module-info.java | 8 ++++++++ gradle/dependencies.gradle | 10 +++++++--- gradle/eclipse.gradle | 13 +++++++++++++ 4 files changed, 47 insertions(+), 5 deletions(-) create mode 100644 caffeine/src/main/java/module-info.java diff --git a/caffeine/build.gradle b/caffeine/build.gradle index 1500af9690..298c620270 100644 --- a/caffeine/build.gradle +++ b/caffeine/build.gradle @@ -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) { @@ -66,6 +79,10 @@ dependencies { javaPoetImplementation libraries.googleJavaFormat } +compileJava { + modularity.inferModulePath = true +} + compileCodeGenJava { gradle.taskGraph.whenReady { enabled = gradle.taskGraph.hasTask('uploadArchives') diff --git a/caffeine/src/main/java/module-info.java b/caffeine/src/main/java/module-info.java new file mode 100644 index 0000000000..99b52f3a55 --- /dev/null +++ b/caffeine/src/main/java/module-info.java @@ -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; +} \ No newline at end of file diff --git a/gradle/dependencies.gradle b/gradle/dependencies.gradle index bc9d89216f..11c547302a 100644 --- a/gradle/dependencies.gradle +++ b/gradle/dependencies.gradle @@ -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', @@ -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}", diff --git a/gradle/eclipse.gradle b/gradle/eclipse.gradle index 43eef673a1..7393d89d0a 100644 --- a/gradle/eclipse.gradle +++ b/gradle/eclipse.gradle @@ -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() +}