Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add required exports to the jar manifest #566

Merged
merged 2 commits into from
Nov 3, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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(' ')))
}
}