forked from palantir/palantir-java-format
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.gradle
More file actions
140 lines (122 loc) · 6.71 KB
/
Copy pathbuild.gradle
File metadata and controls
140 lines (122 loc) · 6.71 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
buildscript {
repositories {
mavenCentral()
gradlePluginPortal()
}
dependencies {
classpath 'com.palantir.jakartapackagealignment:jakarta-package-alignment:0.7.0'
classpath 'com.gradle.publish:plugin-publish-plugin:2.2.1'
classpath 'com.palantir.baseline-error-prone:gradle-baseline-error-prone:0.7.0'
classpath 'com.palantir.baseline:gradle-baseline-java:7.9.0'
classpath 'com.palantir.gradle.failure-reports:gradle-failure-reports:1.21.0'
classpath 'com.palantir.gradle.gitversion:gradle-git-version:5.1.0'
classpath 'com.palantir.gradle.guide:gradle-guide:1.27.0'
classpath 'com.palantir.gradle.idea-configuration:gradle-idea-configuration:0.11.0'
classpath 'com.palantir.gradle.idea-language-injector:gradle-idea-language-injector:0.5.0'
classpath 'com.palantir.javaformat:gradle-palantir-java-format:2.98.0'
classpath 'com.palantir.suppressible-error-prone:gradle-suppressible-error-prone:2.28.0'
classpath 'me.champeau.jmh:jmh-gradle-plugin:0.7.3'
}
}
apply plugin: 'com.palantir.failure-reports'
apply plugin: 'com.palantir.git-version'
apply plugin: 'com.palantir.gradle-guide'
apply plugin: 'com.palantir.idea-language-injector'
// Not the `com.palantir.baseline` aggregate: it also applies baseline-format (Spotless) and
// baseline-class-uniqueness, and both are incompatible with the configuration cache at their
// latest versions — Spotless fails serialising its Groovy extension, checkClassUniqueness casts
// a ResolvingFileCollection to Configuration. The rest of what baseline gives us is applied
// per project below, so error-prone and the JUnit wiring survive.
apply plugin: 'com.palantir.baseline-error-prone-root'
apply plugin: 'com.palantir.baseline-java-versions'
// Maven Central releases: buildSrc/src/main/groovy/open-java-format.release-conventions.gradle.
apply plugin: 'open-java-format.release-conventions'
// GitHub Actions sets GITHUB_REF_TYPE=tag on a tag build; otherwise derive the
// version from git history (needs a full clone: actions/checkout fetch-depth: 0).
//
// Read through providers rather than System.env: the configuration cache tracks a provider as an input
// and invalidates when it changes, while a plain System.env read is invisible to it — a cached
// configuration then keeps handing out the version of whichever environment happened to fill it.
def refType = providers.environmentVariable('GITHUB_REF_TYPE')
def refName = providers.environmentVariable('GITHUB_REF_NAME')
version refType.getOrElse('') == 'tag' ? refName.get() : gitVersion()
// The GraalVM image is built by its own per-platform CI job, never as a side effect of
// `./gradlew build`: an aggregate build must not require a GraalVM toolchain on a machine that
// only wants the jars. Pass -PnativeImage=true to wire it back into the lifecycle tasks — that is
// what .github/workflows/ci.yml's `native` jobs do.
ext.nativeImageRequested = Boolean.parseBoolean(providers.gradleProperty('nativeImage').getOrElse('false'))
// The javac internals the formatter parses with. Was baseline's `moduleJvmArgs`, which is
// dropped because it resolves its extension at execution time and the configuration cache
// forbids that — so the exports are handed to javac and to the test JVMs here instead.
def javacInternalExports = [
'jdk.compiler/com.sun.tools.javac.api',
'jdk.compiler/com.sun.tools.javac.code',
'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',
]
allprojects {
apply plugin: 'com.palantir.baseline-null-away'
apply plugin: 'com.palantir.baseline-encoding'
apply plugin: 'com.palantir.baseline-immutables'
apply plugin: 'com.palantir.baseline-java-compiler-diagnostics'
apply plugin: 'com.palantir.baseline-java-compiler-heap'
apply plugin: 'com.palantir.baseline-java-properties'
apply plugin: 'com.palantir.baseline-prefer-project-modules'
apply plugin: 'com.palantir.baseline-reproducibility'
apply plugin: 'com.palantir.baseline-test-heap'
apply plugin: com.palantir.baseline.plugins.BaselineTesting
apply plugin: 'com.palantir.java-format'
apply plugin: 'com.palantir.jakarta-package-alignment'
// The fork's Maven group (README, "Coordinates"). The Java packages stay com.palantir.javaformat.
group = 'dev.openjavaformat'
version = rootProject.version
tasks.withType(JavaCompile).configureEach {
options.compilerArgs.addAll(javacInternalExports.collect { "--add-exports=${it}=ALL-UNNAMED".toString() })
}
tasks.withType(Test).configureEach {
jvmArgs(javacInternalExports.collect { "--add-exports=${it}=ALL-UNNAMED".toString() })
// The short form gave CI logs only "FormatterException at FormatterIntegrationTest.java:76", never what
// the formatter complained about, nor the output of a TestKit build that failed.
testLogging.exceptionFormat = 'full'
}
tasks.withType(Javadoc).configureEach {
options.addMultilineStringsOption('-add-exports')
.setValue(javacInternalExports.collect { "${it}=ALL-UNNAMED".toString() })
// baseline used to silence doclint; these sources carry inherited javadoc from
// google-java-format that has never satisfied it (unknown tags, malformed HTML).
options.addStringOption('Xdoclint:none', '-quiet')
}
repositories {
mavenCentral() { metadataSources { mavenPom(); ignoreGradleMetadataRedirection() } }
gradlePluginPortal()
}
}
subprojects {
apply plugin: 'java-library'
dependencies {
// Gives a version to the JUnit artifacts that plugins add without one.
testImplementation platform(libs.junit.bom)
}
tasks.withType(Checkstyle).configureEach {
enabled = false
}
tasks.withType(JavaCompile).configureEach {
options.errorprone.disable 'PreconditionsConstantMessage', 'PreferSafeLoggableExceptions', 'PreferSafeLoggingPreconditions'
options.errorprone.disable 'StrictUnusedVariable'
}
// Run `./gradlew test -Drecreate=true` to recreate all the expected
// generated code that we have checked into the repo.
tasks.withType(Test).configureEach {
systemProperty 'recreate', System.getProperty('recreate', 'false')
}
}
// The JDK the tests run on, and with it the javac whose internals the formatter parses with. The code is
// compiled for 21 whatever this says. CI's `jdk` jobs pass -PjavaRuntime=25 and so on.
ext.javaRuntime = providers.gradleProperty('javaRuntime').getOrElse('21')
javaVersions {
libraryTarget = 21
runtime = javaRuntime
}