Skip to content

Commit 8bb42e3

Browse files
committed
Fix Java module descriptor configuration
1 parent 7fbe829 commit 8bb42e3

File tree

5 files changed

+79
-3
lines changed

5 files changed

+79
-3
lines changed

build.gradle.kts

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ plugins {
5757
id("com.asarkar.gradle.build-time-tracker") version "3.0.1"
5858
id("org.jetbrains.dokka") version "1.6.21"
5959
id("ru.vyarus.use-python") version "2.3.0"
60+
id("org.moditect.gradleplugin") version "1.0.0-rc3"
6061
id("com.github.johnrengelman.shadow") version "7.1.2"
6162
id("io.github.gradle-nexus.publish-plugin") version "1.1.0"
6263
`maven-publish`
@@ -98,6 +99,27 @@ tasks.test {
9899
maxParallelForks = 1
99100
}
100101

102+
// Suppress warnings about incubating test suites feature
103+
@Suppress("UnstableApiUsage")
104+
testing {
105+
suites {
106+
// Separate test suite for module testing
107+
val testModular by registering(JvmTestSuite::class) {
108+
dependencies {
109+
implementation(project)
110+
}
111+
}
112+
}
113+
}
114+
115+
// Module tests require Java 9 or newer to compile and execute
116+
if (JavaVersion.current().isJava9Compatible) {
117+
tasks.check {
118+
@Suppress("UnstableApiUsage")
119+
dependsOn(testing.suites.named("testModular"))
120+
}
121+
}
122+
101123
tasks.jacocoTestReport {
102124
dependsOn("test")
103125
reports {
@@ -390,3 +412,19 @@ signing {
390412
repositories {
391413
mavenCentral()
392414
}
415+
416+
tasks.addMainModuleInfo {
417+
version = project.version
418+
// Create Multi-Release JAR with Java 9 as lowest version
419+
jvmVersion.set("9")
420+
// Overwrite the existing JAR file with the modular one
421+
overwriteExistingFiles.set(true)
422+
module {
423+
moduleInfoFile = File("$projectDir/src/main/java-9/module-info.java")
424+
}
425+
}
426+
// Workaround to avoid circular dependencies between tasks, see https://github.com/moditect/moditect-gradle-plugin/issues/14
427+
project.afterEvaluate {
428+
val compileJavaTask = tasks.compileJava.get()
429+
compileJavaTask.setDependsOn(compileJavaTask.dependsOn - tasks.addDependenciesModuleInfo.get())
430+
}

src/main/java-9/module-info.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
module com.github.pemistahl.lingua {
2+
exports com.github.pemistahl.lingua.api;
3+
4+
requires kotlin.stdlib;
5+
6+
requires it.unimi.dsi.fastutil;
7+
requires okio;
8+
9+
// Moshi accesses JSON serializer using reflection; must open the package
10+
// TODO: Once new Moshi version has module names, change it to `opens ... to com.squareup.moshi`
11+
// and comment in the `requires` declarations below
12+
opens com.github.pemistahl.lingua.internal;
13+
// requires com.squareup.moshi;
14+
// requires com.squareup.moshi.kotlin;
15+
}

src/main/resources/META-INF/versions/9/module-info.java

Lines changed: 0 additions & 3 deletions
This file was deleted.

src/testModular/java/module-info.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
// Open complete module for reflection to allow JUnit to access the packages
2+
open module test {
3+
requires com.github.pemistahl.lingua;
4+
5+
requires org.junit.jupiter.api;
6+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package test;
2+
3+
import com.github.pemistahl.lingua.api.*;
4+
import org.junit.jupiter.api.Test;
5+
6+
import static com.github.pemistahl.lingua.api.Language.*;
7+
import static org.junit.jupiter.api.Assertions.assertEquals;
8+
9+
/**
10+
* Tests basic Lingua functionality. The main purpose of this test is to verify that the
11+
* packages can be accessed from a different module.
12+
*/
13+
class LinguaTest {
14+
@Test
15+
void test() {
16+
LanguageDetector detector = LanguageDetectorBuilder.fromLanguages(ENGLISH, FRENCH, GERMAN, SPANISH).build();
17+
Language detectedLanguage = detector.detectLanguageOf("languages are awesome");
18+
assertEquals(ENGLISH, detectedLanguage);
19+
}
20+
}

0 commit comments

Comments
 (0)