Skip to content

Commit

Permalink
Fix Java module descriptor configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
Marcono1234 committed May 28, 2022
1 parent 7fbe829 commit 30c86bc
Show file tree
Hide file tree
Showing 5 changed files with 80 additions and 3 deletions.
38 changes: 38 additions & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ plugins {
id("com.asarkar.gradle.build-time-tracker") version "3.0.1"
id("org.jetbrains.dokka") version "1.6.21"
id("ru.vyarus.use-python") version "2.3.0"
id("org.moditect.gradleplugin") version "1.0.0-rc3"
id("com.github.johnrengelman.shadow") version "7.1.2"
id("io.github.gradle-nexus.publish-plugin") version "1.1.0"
`maven-publish`
Expand Down Expand Up @@ -98,6 +99,27 @@ tasks.test {
maxParallelForks = 1
}

// Suppress warnings about incubating test suites feature
@Suppress("UnstableApiUsage")
testing {
suites {
// Separate test suite for module testing
val testModular by registering(JvmTestSuite::class) {
dependencies {
implementation(project)
}
}
}
}

// Module tests require Java 9 or newer to compile and execute
if (JavaVersion.current().isJava9Compatible) {
tasks.check {
@Suppress("UnstableApiUsage")
dependsOn(testing.suites.named("testModular"))
}
}

tasks.jacocoTestReport {
dependsOn("test")
reports {
Expand Down Expand Up @@ -250,6 +272,22 @@ tasks.register<PythonTask>("writeAccuracyTable") {
command = "src/python-scripts/write_accuracy_table.py"
}

tasks.addMainModuleInfo {
version = project.version
// Create Multi-Release JAR with Java 9 as lowest version
jvmVersion.set("9")
// Overwrite the output JAR file (if any) from a previous Gradle execution
overwriteExistingFiles.set(true)
module {
moduleInfoFile = File("$projectDir/src/main/java-9/module-info.java")
}
}
// Workaround to avoid circular dependencies between tasks, see https://github.com/moditect/moditect-gradle-plugin/issues/14
project.afterEvaluate {
val compileJavaTask = tasks.compileJava.get()
compileJavaTask.setDependsOn(compileJavaTask.dependsOn - tasks.addDependenciesModuleInfo.get())
}

tasks.withType<DokkaTask>().configureEach {
dokkaSourceSets.configureEach {
jdkVersion.set(6)
Expand Down
15 changes: 15 additions & 0 deletions src/main/java-9/module-info.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
module com.github.pemistahl.lingua {
exports com.github.pemistahl.lingua.api;

requires kotlin.stdlib;

requires it.unimi.dsi.fastutil;
requires okio;

// Moshi accesses JSON serializer using reflection; must open the package
// TODO: Once new Moshi version has module names, change it to `opens ... to com.squareup.moshi`
// and comment in the `requires` declarations below
opens com.github.pemistahl.lingua.internal;
// requires com.squareup.moshi;
// requires com.squareup.moshi.kotlin;
}
3 changes: 0 additions & 3 deletions src/main/resources/META-INF/versions/9/module-info.java

This file was deleted.

6 changes: 6 additions & 0 deletions src/testModular/java/module-info.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// Open complete module for reflection to allow JUnit to access the packages
open module test {
requires com.github.pemistahl.lingua;

requires org.junit.jupiter.api;
}
21 changes: 21 additions & 0 deletions src/testModular/java/test/LinguaTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package test;

import com.github.pemistahl.lingua.api.*;
import org.junit.jupiter.api.Test;

import static com.github.pemistahl.lingua.api.Language.*;
import static org.junit.jupiter.api.Assertions.assertEquals;

/**
* Tests basic Lingua functionality. The main purpose of this test is to verify that the
* packages can be accessed from a different module and that Lingua specifies all required
* modules and can be used successfully.
*/
class LinguaTest {
@Test
void test() {
LanguageDetector detector = LanguageDetectorBuilder.fromLanguages(ENGLISH, FRENCH, GERMAN, SPANISH).build();
Language detectedLanguage = detector.detectLanguageOf("languages are awesome");
assertEquals(ENGLISH, detectedLanguage);
}
}

0 comments on commit 30c86bc

Please sign in to comment.