Skip to content

Commit

Permalink
Creating multi release jar instead of just mixing classes compiled by…
Browse files Browse the repository at this point in the history
… different versions of javac.

Note: bnd had to be updated to add support for this, and the new bnd requires JDK 17. So, now the minimum JDK required to run the build is 17.

Also rat was updated and new xalan dependencies were added (this was forced on us by the bnd update).
  • Loading branch information
kelemen committed Jun 3, 2024
1 parent b448ea6 commit 7b1dc7b
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 8 deletions.
4 changes: 2 additions & 2 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,14 @@
import java.io.FileOutputStream
import java.nio.charset.StandardCharsets
import java.nio.file.Files
import java.util.*
import java.util.Properties
import java.util.stream.Collectors

plugins {
`freemarker-root`
`maven-publish`
signing
id("biz.aQute.bnd.builder") version "6.1.0"
id("biz.aQute.bnd.builder") version "7.0.0"
id("eclipse")
}

Expand Down
5 changes: 4 additions & 1 deletion buildSrc/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,8 @@ dependencies {
implementation(gradleApi())

implementation("org.apache.freemarker.docgen:freemarker-docgen-core:0.0.2-SNAPSHOT")
implementation("org.nosphere.apache:creadur-rat-gradle:0.7.0")
implementation("org.nosphere.apache:creadur-rat-gradle:0.8.1")
// Xalan dependencies are required by rat even though it does not declare a dependency on them.
implementation("xalan:xalan:2.7.3")
implementation("xalan:serializer:2.7.3")
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

package freemarker.build

import java.util.concurrent.atomic.AtomicBoolean
import org.gradle.api.NamedDomainObjectProvider
import org.gradle.api.Project
import org.gradle.api.artifacts.VersionCatalogsExtension
Expand All @@ -35,11 +36,14 @@ import org.gradle.api.tasks.compile.JavaCompile
import org.gradle.api.tasks.javadoc.Javadoc
import org.gradle.jvm.toolchain.JavaLanguageVersion
import org.gradle.jvm.toolchain.JavaToolchainService
import org.gradle.kotlin.dsl.*
import org.gradle.kotlin.dsl.dependencies
import org.gradle.kotlin.dsl.named
import org.gradle.kotlin.dsl.register
import org.gradle.kotlin.dsl.setProperty
import org.gradle.kotlin.dsl.the
import org.gradle.language.base.plugins.LifecycleBasePlugin
import org.gradle.language.jvm.tasks.ProcessResources
import org.gradle.testing.base.TestingExtension
import java.util.concurrent.atomic.AtomicBoolean

private const val TEST_UTILS_SOURCE_SET_NAME = "test-utils"

Expand Down Expand Up @@ -332,7 +336,8 @@ class FreemarkerRootExtension constructor(

allConfiguredSourceSetNamesRef.add(sourceSetName)

FreemarkerModuleDef(context, this, generated, sourceSetName, JavaLanguageVersion.of(sourceSetVersion)).apply {
val parsedSourceSetVersion = JavaLanguageVersion.of(sourceSetVersion)
FreemarkerModuleDef(context, this, generated, sourceSetName, parsedSourceSetVersion).apply {
sourceSet.apply {
if (generated) {
java.setSrcDirs(emptyList<String>())
Expand All @@ -350,7 +355,13 @@ class FreemarkerRootExtension constructor(

tasks.apply {
named<Jar>(mainSourceSet.sourcesJarTaskName) { from(sourceSet.allSource) }
named<Jar>(JavaPlugin.JAR_TASK_NAME) { from(sourceSet.output) }
named<Jar>(JavaPlugin.JAR_TASK_NAME) {
from(sourceSet.output) {
if (parsedSourceSetVersion.compareTo(JavaLanguageVersion.of(javaVersion)) > 0) {
into("META-INF/versions/${parsedSourceSetVersion.asInt()}")
}
}
}
named<Javadoc>(JavaPlugin.JAVADOC_TASK_NAME) { source(sourceSet.java) }
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,12 @@ import org.gradle.api.publish.maven.tasks.AbstractPublishToMaven
import org.gradle.api.tasks.SourceSet
import org.gradle.api.tasks.bundling.Jar
import org.gradle.jvm.toolchain.JavaLanguageVersion
import org.gradle.kotlin.dsl.*
import org.gradle.kotlin.dsl.attributes
import org.gradle.kotlin.dsl.configure
import org.gradle.kotlin.dsl.filter
import org.gradle.kotlin.dsl.named
import org.gradle.kotlin.dsl.the
import org.gradle.kotlin.dsl.withType
import org.gradle.language.base.plugins.LifecycleBasePlugin
import org.gradle.language.jvm.tasks.ProcessResources

Expand Down Expand Up @@ -66,6 +71,9 @@ open class FreemarkerRootPlugin : Plugin<Project> {

named<Jar>(mainSourceSet.sourcesJarTaskName) {
from(resourceTemplatesDir)
manifest.attributes(
"Multi-Release" to "true"
)
}

withType<org.nosphere.apache.rat.RatTask>() {
Expand Down

0 comments on commit 7b1dc7b

Please sign in to comment.