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
91 lines (78 loc) · 4.1 KB
/
Copy pathbuild.gradle
File metadata and controls
91 lines (78 loc) · 4.1 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
buildscript {
repositories {
mavenCentral()
gradlePluginPortal()
}
dependencies {
classpath 'com.gradle.publish:plugin-publish-plugin:2.2.1'
// The released open-java-format formats this repository, not the one being built here.
classpath 'dev.openjavaformat:gradle-open-java-format:2.98.0.5'
classpath 'me.champeau.jmh:jmh-gradle-plugin:0.7.3'
}
}
// 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):
// the nearest tag, the commits since it and the hash, `.dirty` with uncommitted changes.
//
// 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')
def gitDescribe = providers.exec {
commandLine 'git', 'describe', '--tags', '--always', '--first-parent', '--abbrev=7', '--dirty=.dirty'
}.standardOutput.asText.map { it.trim() }
version refType.getOrElse('') == 'tag' ? refName.get() : gitDescribe.get()
// 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, handed to javac and to the test JVMs.
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: 'dev.openjavaformat.java-format'
// 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() })
// These sources carry inherited javadoc from google-java-format that has never
// satisfied doclint (unknown tags, malformed HTML).
options.addStringOption('Xdoclint:none', '-quiet')
}
repositories {
mavenCentral() { metadataSources { mavenPom(); ignoreGradleMetadataRedirection() } }
gradlePluginPortal()
}
}
subprojects {
apply plugin: 'java-library'
// Java toolchains, javac and test settings; Error Prone. Both in buildSrc/src/main/groovy.
apply plugin: 'open-java-format.java-conventions'
apply plugin: 'open-java-format.error-prone-conventions'
dependencies {
// Gives a version to the JUnit artifacts that useJUnitJupiter() adds without one.
testImplementation platform(libs.junit.bom)
}
}