forked from remkop/picocli
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.gradle
248 lines (223 loc) · 9.61 KB
/
build.gradle
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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
import aQute.bnd.gradle.Bundle
group 'info.picocli'
description 'Java command line parser with both an annotations API and a programmatic API. Usage help with ANSI styles and colors. Autocomplete. Nested subcommands. Easily included as source to avoid adding a dependency.'
version "$projectVersion"
ext.moduleName = 'info.picocli'
buildscript {
apply from: 'dependencies.gradle'
repositories {
gradlePluginPortal()
mavenCentral()
}
dependencies {
classpath "org.asciidoctor:asciidoctor-gradle-jvm:$asciidoctorGradlePluginVersion"
classpath 'org.asciidoctor:asciidoctorj-pdf:2.3.15'
classpath "org.beryx:badass-jar:2.0.0"
classpath 'biz.aQute.bnd:biz.aQute.bnd.gradle:6.4.0'
classpath "io.codearte.gradle.nexus:gradle-nexus-staging-plugin:0.30.0"
classpath "net.ltgt.gradle:gradle-errorprone-plugin:3.1.0"
}
}
apply plugin: 'io.codearte.nexus-staging'
if (System.getenv('MAVEN_OSS_USER')) { // on home system
apply plugin: 'biz.aQute.bnd.builder'
} else {
try { // otherwise, only apply if available
Class.forName('aQute.bnd.gradle.BndPlugin')
Class.forName('aQute.bnd.build.Project')
apply plugin: 'biz.aQute.bnd.builder'
} catch (Throwable ignored) {}
}
pluginManager.withPlugin('biz.aQute.bnd.builder') { // if plugin applied, execute this action
configurations {
bundleCompile
baseline
}
dependencies {
baseline('group': group, 'name': jar.archiveBaseName) {
version {
strictly "(,${jar.archiveVersion}["
}
transitive = false
}
}
sourceSets {
bundle
}
task bundle(type: Bundle) {
from sourceSets.bundle.output
bndfile = 'bnd.bnd'
sourceSet = sourceSets.bundle
}
}
allprojects {
apply plugin: 'java'
apply plugin: 'java-library' // to avoid https://github.com/gradle/gradle/issues/1118
apply plugin: 'org.beryx.jar' // for compiling module-info on Java 8
// https://errorprone.info/docs/installation requires Java 11+
if (JavaVersion.current().isJava11Compatible()) {
apply plugin: "net.ltgt.errorprone"
dependencies {
errorprone("com.google.errorprone:error_prone_core:2.27.1")
}
tasks.withType(JavaCompile).configureEach {
options.errorprone.disableAllWarnings = true
}
}
if (!JavaVersion.current().isJava9Compatible()) {
sourceCompatibility = 1.5
targetCompatibility = 1.5
} else { // from Java 9 and up
sourceCompatibility = 1.8
targetCompatibility = 1.8
// tasks.withType(JavaCompile).configureEach {
// javaCompiler = javaToolchains.compilerFor {
// languageVersion = JavaLanguageVersion.of(JavaVersion.current().majorVersion)
// }
// }
}
compileJava.options.encoding = "UTF-8"
compileTestJava.options.encoding = "UTF-8"
repositories {
maven { url 'https://repo.spring.io/libs-snapshot' }
mavenCentral()
}
configurations.all {
resolutionStrategy {
// avoid "Could not resolve junit:junit-dep:[4.9,)" caused by stefanbirkner:system-rules when building offline
force "junit:junit-dep:$junitDepVersion"
}
}
dependencies {
testImplementation supportDependencies.jansi
testImplementation supportDependencies.groovy
testImplementation supportDependencies.junit
testImplementation supportDependencies.hamcrestCore
testImplementation supportDependencies.systemRules
testImplementation supportDependencies.junitParams
}
tasks.withType(JavaCompile) {
options.compilerArgs << '-Xlint:unchecked' << '-Xlint:deprecation'
}
javadoc.destinationDir = file("build/docs/apidocs")
javadoc.options.addStringOption('Xdoclint:none', '-quiet')
// Workaround frpm https://bugs.openjdk.org/browse/JDK-4973681
javadoc.options.addStringOption('sourcepath', 'src/main/java')
if (!project.name in ['picocli-examples', 'picocli-annotation-processing-tests']) {
//sourceSets.main.java.srcDirs = ['src/main/java', 'src/main/java9']
compileJava {
inputs.property("moduleName", moduleName)
// doFirst {
// logger.info("Java version is " + JavaVersion.current())
// if (JavaVersion.current().isJava9Compatible()) {
// options.compilerArgs = [
// '--module-path', classpath.asPath,
// ]
// }
// // classpath = files()
// classpath = sourceSets.main.runtimeClasspath
// logger.info("options.compilerArgs is " + options.compilerArgs)
// logger.info("classpath is " + classpath.files)
// }
}
moduleConfig {
// copy module-info.class to META-INF/versions/9
multiReleaseVersion = 9
moduleInfoPath = 'src/main/java9/module-info.java'
version = project.version
neverCompileModuleInfo = true
}
}
normalization {
runtimeClasspath {
metaInf {
ignoreAttribute("Bnd-LastModified")
}
}
}
}
//sourceSets.main.java.srcDirs = ['src/main/java', 'src/main/java9']
compileJava {
inputs.property("moduleName", moduleName)
// doFirst {
// if (JavaVersion.current().isJava9Compatible()) {
// options.compilerArgs = [
// '--module-path', classpath.asPath,
// ]
// }
// classpath = files()
// }
}
moduleConfig {
// copy module-info.class to META-INF/versions/9
multiReleaseVersion = 9
moduleInfoPath = 'src/main/java9/module-info.java'
version = project.version
neverCompileModuleInfo = true
}
jar {
manifest {
attributes 'Specification-Title' : 'picocli',
'Specification-Vendor' : 'Remko Popma',
'Specification-Version' : archiveVersion.get(),
'Implementation-Title' : 'picocli',
'Implementation-Vendor' : 'Remko Popma',
'Implementation-Version': archiveVersion.get(),
'Main-Class' : 'picocli.AutoComplete'
}
}
configurations {
apiElements {
canBeConsumed = true
canBeResolved = false
attributes {
attribute(Category.CATEGORY_ATTRIBUTE, objects.named(Category, Category.LIBRARY))
attribute(Usage.USAGE_ATTRIBUTE, objects.named(Usage, Usage.JAVA_RUNTIME))
attribute(Bundling.BUNDLING_ATTRIBUTE, objects.named(Bundling, Bundling.EXTERNAL))
// not sure why the below is needed, but when building with Java 8, using VERSION_1_5 gives this error:
//
// Could not determine the dependencies of task ':picocli-codegen:compileTestJava'.
//> Could not resolve all task dependencies for configuration ':picocli-codegen:testCompileClasspath'.
// > Could not resolve project :.
// Required by:
// project :picocli-codegen
// > The consumer was configured to find an API of a library compatible with Java 6,
// preferably in the form of class files, preferably optimized for standard JVMs, and its dependencies declared externally.
// However we cannot choose between the following variants of project ::
// - apiElements
// - runtimeElements
// All of them match the consumer attributes:
// - Variant 'apiElements' capability info.picocli:picocli:4.7.0-SNAPSHOT declares a runtime of a library compatible with Java 5, packaged as a jar, and its dependencies declared externally:
// - Unmatched attribute:
// - Doesn't say anything about its target Java environment (preferred optimized for standard JVMs)
// - Variant 'runtimeElements' capability info.picocli:picocli:4.7.0-SNAPSHOT declares a runtime of a library compatible with Java 5, packaged as a jar, and its dependencies declared externally:
// - Unmatched attribute:
// - Doesn't say anything about its target Java environment (preferred optimized for standard JVMs)
attribute(TargetJvmVersion.TARGET_JVM_VERSION_ATTRIBUTE, new Integer(JavaVersion.VERSION_1_6.majorVersion))
}
}
}
// jacoco 0.8.2 does not work with Java 13; gradle 4.x has no JavaVersion enum value for Java 12
if (JavaVersion.current().isJava11Compatible()) {
project.logger.lifecycle("skipping jacoco test for Java version ${JavaVersion.current()}")
} else {
project.logger.lifecycle("applying jacoco build file for Java version ${JavaVersion.current()}")
apply from: "gradle/jacoco.gradle"
}
if (JavaVersion.current().isCompatibleWith(JavaVersion.VERSION_18)) {
// https://github.com/remkop/picocli/issues/1503
test { // explicitly enable security manager on Java 18 for System.exit tests
systemProperty "java.security.manager", "allow"
}
}
// javadoc and asciidoc customization
apply from: "${rootProject.projectDir}/gradle/docs.gradle"
// publishing-related
ext {
PUBLISH_GROUP_ID = group
PUBLISH_ARTIFACT_ID = project.name
PUBLISH_VERSION = "$projectVersion"
}
apply from: "${rootProject.projectDir}/gradle/publish-mavencentral.gradle"
// release-related custom gradle tasks and release procedure steps
apply from: "${rootProject.projectDir}/gradle/release-tasks.gradle"