Skip to content

Commit

Permalink
Gradle: slighltly simpler build.
Browse files Browse the repository at this point in the history
  • Loading branch information
carlosame committed Aug 12, 2021
1 parent 7d6443f commit e293823
Showing 1 changed file with 29 additions and 44 deletions.
73 changes: 29 additions & 44 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ sourceSets {
}

java {
sourceCompatibility = JavaVersion.VERSION_11
sourceCompatibility = JavaVersion.VERSION_1_8
withJavadocJar()
withSourcesJar()
registerFeature('dtdparse') {
Expand All @@ -51,44 +51,44 @@ dependencies {
testImplementation "junit:junit:4.13.1"
}

tasks.register('jvmVersionAttribute') {
description = "Set the correct 'org.gradle.jvm.version' attribute"
def jvmVersionAttribute = Attribute.of('org.gradle.jvm.version', Integer)
configurations.each {
if (it.canBeConsumed) {
def categoryAttr = it.attributes.getAttribute(Category.CATEGORY_ATTRIBUTE)
if (categoryAttr != null && categoryAttr.name == Category.LIBRARY) {
def usageAttr = it.attributes.getAttribute(Usage.USAGE_ATTRIBUTE)
if (usageAttr != null && (usageAttr.name == Usage.JAVA_API
|| usageAttr.name == Usage.JAVA_RUNTIME)) {
it.attributes.attribute(jvmVersionAttribute, 8)
}
}
repositories {
maven {
url = uri('https://repo.maven.apache.org/maven2/')
}
maven {
url "https://css4j.github.io/maven/"
mavenContent {
releasesOnly()
}
content {
includeGroup 'io.sf.carte'
includeGroup 'io.sf.jclf'
}
}
}

compileJava.dependsOn tasks.jvmVersionAttribute
tasks.compileJava {
excludes += ['module-info.java']
modularity.inferModulePath = false
}

tasks.register('compileLegacyJava', JavaCompile) {
description = 'Compile to Java 8 bytecode, except module-info'
tasks.register('compileModuleInfo', JavaCompile) {
description = 'Compile module-info to Java 11 bytecode'
dependsOn tasks.compileJava
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
source = tasks.compileJava.stableSources
classpath = tasks.compileJava.classpath
destinationDirectory = tasks.compileJava.destinationDirectory
modularity.inferModulePath = false
includes = tasks.compileJava.includes
excludes = tasks.compileJava.excludes
excludes += ['module-info.java']
sourceCompatibility = JavaVersion.VERSION_11
targetCompatibility = JavaVersion.VERSION_11
source = sourceSets.main.java
classpath = sourceSets.main.compileClasspath
destinationDirectory = sourceSets.main.java.destinationDirectory
modularity.inferModulePath = true
includes = ['module-info.java']
}

classes.dependsOn compileLegacyJava
classes.dependsOn compileModuleInfo

// Check bytecode version, in case some other task screws it
tasks.register('checkLegacyJava') {
description = 'Check Java 8 bytecode'
description = 'Check that classes are Java 8 bytecode (except module-info)'
def classdir = sourceSets.main.output.classesDirs.files.stream().findAny().get()
def classfiles = fileTree(classdir).matching({it.exclude('module-info.class')}).files
doFirst() {
Expand All @@ -108,22 +108,6 @@ tasks.register('checkLegacyJava') {

classes.finalizedBy checkLegacyJava

repositories {
maven {
url = uri('https://repo.maven.apache.org/maven2/')
}
maven {
url "https://css4j.github.io/maven/"
mavenContent {
releasesOnly()
}
content {
includeGroup 'io.sf.carte'
includeGroup 'io.sf.jclf'
}
}
}

tasks.register('lineEndingConversion', CRLFConvert) {
description 'Convert LICENSE.txt to Windows line endings'
file "$rootDir/LICENSE.txt"
Expand All @@ -149,6 +133,7 @@ tasks.withType(Javadoc) {
options.addStringOption('Xdoclint:none', '-quiet')
options.addStringOption('encoding', 'UTF-8')
options.addStringOption('charset', 'UTF-8')
options.links 'https://docs.oracle.com/en/java/javase/11/docs/api/'
}

// Reproducible build
Expand Down

0 comments on commit e293823

Please sign in to comment.