Skip to content

Commit

Permalink
Add required exports to the jar manifest (#566)
Browse files Browse the repository at this point in the history
Add required exports to the jar manifest
  • Loading branch information
carterkozak authored Nov 3, 2021
1 parent 9025a22 commit aa7a699
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 10 deletions.
5 changes: 5 additions & 0 deletions changelog/@unreleased/pr-566.v2.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
type: improvement
improvement:
description: Add required exports to the jar manifest
links:
- https://github.com/palantir/palantir-java-format/pull/566
38 changes: 28 additions & 10 deletions palantir-java-format/build.gradle
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
import java.util.function.Function
import java.util.stream.Collectors

apply plugin: 'application'
apply plugin: 'com.palantir.external-publish-jar'

Expand Down Expand Up @@ -30,19 +33,26 @@ dependencies {
annotationProcessor 'org.derive4j:derive4j'
}

def exports = [
'jdk.compiler/com.sun.tools.javac.file',
'jdk.compiler/com.sun.tools.javac.main',
'jdk.compiler/com.sun.tools.javac.parser',
'jdk.compiler/com.sun.tools.javac.tree',
'jdk.compiler/com.sun.tools.javac.util',
'jdk.compiler/com.sun.tools.javac.code',
'jdk.compiler/com.sun.tools.javac.api'
]

tasks.withType(JavaCompile).configureEach {
options.errorprone.disable 'StrictUnusedVariable'

options.compilerArgs += [
// Allow access to internal javac apis
'--add-exports=jdk.compiler/com.sun.tools.javac.file=ALL-UNNAMED',
'--add-exports=jdk.compiler/com.sun.tools.javac.main=ALL-UNNAMED',
'--add-exports=jdk.compiler/com.sun.tools.javac.parser=ALL-UNNAMED',
'--add-exports=jdk.compiler/com.sun.tools.javac.tree=ALL-UNNAMED',
'--add-exports=jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED',
'--add-exports=jdk.compiler/com.sun.tools.javac.code=ALL-UNNAMED',
'--add-exports=jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED'
]
// Allow access to internal javac apis
options.compilerArgs += exports.stream().map(new Function<String, String>() {
@Override
String apply(String value) {
return "--add-exports=${value}=ALL-UNNAMED"
}
}).collect(Collectors.toList())

if (JavaVersion.current() < JavaVersion.VERSION_14) {
excludes = ['**/Java14InputAstVisitor.java']
Expand Down Expand Up @@ -71,3 +81,11 @@ tasks.test {
idea {
module.languageLevel = new org.gradle.plugins.ide.idea.model.IdeaLanguageLevel(14)
}

// This block may be replaced by BaselineExportsExtension exports
// once https://github.com/gradle/gradle/issues/18824 is resolved.
jar {
manifest {
attributes('Add-Exports': exports.stream().collect(Collectors.joining(' ')))
}
}

0 comments on commit aa7a699

Please sign in to comment.