Skip to content

Commit 3086af3

Browse files
committed
Gradle: declare a jvm.version attribute.
1 parent 5e4e9fa commit 3086af3

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

buildSrc/src/main/groovy/css4j.java-conventions.gradle

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,23 @@ java {
5757
withSourcesJar()
5858
}
5959

60+
tasks.register('jvmVersionAttribute') {
61+
description = "Set the correct 'org.gradle.jvm.version' attribute"
62+
def jvmVersionAttribute = Attribute.of('org.gradle.jvm.version', Integer)
63+
configurations.each {
64+
if (it.canBeConsumed) {
65+
def categoryAttr = it.attributes.getAttribute(Category.CATEGORY_ATTRIBUTE)
66+
if (categoryAttr != null && categoryAttr.name == Category.LIBRARY) {
67+
def usageAttr = it.attributes.getAttribute(Usage.USAGE_ATTRIBUTE)
68+
if (usageAttr != null && (usageAttr.name == Usage.JAVA_API
69+
|| usageAttr.name == Usage.JAVA_RUNTIME)) {
70+
it.attributes.attribute(jvmVersionAttribute, 8)
71+
}
72+
}
73+
}
74+
}
75+
}
76+
6077
tasks.register('compileLegacyJava', JavaCompile) {
6178
description = 'Compile to Java 8 bytecode, except module-info'
6279
dependsOn tasks.compileJava

0 commit comments

Comments
 (0)