Skip to content

Commit b4b8047

Browse files
authored
Modernize and move error prone gradle plugin to Java (#15305)
* Moved lucene.validation.gradle-versions-cleanup.gradle to a Java plugin. * Add versionCatalogUpdate to build-infra-shadow. * Removed extra prop and replaced it with a provider from buildOptions. * Completely rewrite the error-prone plugin. Add consistency checks against actual ErrorProne version so that we keep the code synced on updates.
1 parent 7a663d6 commit b4b8047

15 files changed

+1131
-791
lines changed
Lines changed: 20 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
import org.apache.lucene.gradle.plugins.LuceneGradlePlugin
2+
import org.apache.lucene.gradle.plugins.globals.LuceneBuildGlobalsExtension
3+
14
/*
25
* Licensed to the Apache Software Foundation (ASF) under one or more
36
* contributor license agreements. See the NOTICE file distributed with
@@ -25,44 +28,12 @@ repositories {
2528
}
2629

2730
apply from: rootProject.file("build-tools/build-infra/ecj-source.gradle")
28-
29-
// Convert a plugin dependency to a regular dependency so that we can
30-
// use [plugins] section in the top-level toml but declare regular
31-
// project dependencies here.
32-
static Provider<String> plugin(Provider<PluginDependency> plugin) {
33-
return plugin.map {
34-
if (it.pluginId == "de.thetaphi.forbiddenapis") {
35-
// Uwe's forbiddenapis is on Maven Central, directly.
36-
return "de.thetaphi:forbiddenapis:${it.version}".toString()
37-
} else {
38-
// maven artifact pattern for gradle's plugin repositories.
39-
return "${it.pluginId}:${it.pluginId}.gradle.plugin:${it.version}".toString()
40-
}
41-
}
42-
}
31+
apply from: rootProject.file("build-tools/build-infra/declare-dependencies.gradle")
4332

4433
dependencies {
45-
implementation gradleApi()
46-
implementation localGroovy()
47-
4834
// seems to be required by gradle apis, otherwise compilation fails even though
4935
// we don't use it.
5036
compileOnly ("com.google.code.findbugs:findbugs-annotations:3.0.1")
51-
52-
implementation deps.commons.codec
53-
implementation deps.randomizedtesting.runner
54-
implementation deps.zstd
55-
56-
implementation deps.gjf
57-
implementation deps.jgit
58-
implementation deps.ecj
59-
60-
implementation plugin(deps.plugins.carrotsearch.buildopts)
61-
implementation plugin(deps.plugins.carrotsearch.dependencychecks)
62-
implementation plugin(deps.plugins.forbiddenapis)
63-
implementation plugin(deps.plugins.spotless)
64-
implementation plugin(deps.plugins.undercouch.download)
65-
implementation plugin(deps.plugins.jacocolog)
6637
}
6738

6839
tasks.matching {
@@ -72,11 +43,25 @@ tasks.matching {
7243
"validateJarChecksums",
7344
"validateJarLicenses",
7445
"collectJarInfos",
75-
// we do need to compile the sources so that forbidden apis are applied (?)
76-
// "compileJava",
46+
// "compileJava", we do need to compile the sources so that forbidden apis are applied.
7747
"compileTestJava",
7848
"assemble"
7949
]
8050
}.configureEach {
8151
enabled = false
8252
}
53+
54+
55+
// This redirects build-infra-shadow's main sources at build-infra sources so that we can
56+
// reapply the build plugin to ourselves (chicken and egg problem - you can't apply a plugin
57+
// to itself).
58+
def buildGlobals = getExtensions().getByType(LuceneBuildGlobalsExtension.class)
59+
if (!buildGlobals.getIntellijIdea().get().isIdea()) {
60+
sourceSets.named("main").configure {
61+
java.setSrcDirs([
62+
LuceneGradlePlugin.getProjectRootPath(project)
63+
.resolve("build-tools/build-infra/src/main/java")
64+
.toFile()
65+
])
66+
}
67+
}

build-tools/build-infra/build.gradle

Lines changed: 1 addition & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -57,46 +57,7 @@ gradlePlugin {
5757
}
5858
}
5959

60-
// Convert a plugin dependency to a regular dependency so that we can
61-
// use [plugins] section in the top-level toml but declare regular
62-
// project dependencies here.
63-
static Provider<String> plugin(Provider<PluginDependency> plugin) {
64-
return plugin.map {
65-
if (it.pluginId == "de.thetaphi.forbiddenapis") {
66-
// Uwe's forbiddenapis is on Maven Central, directly.
67-
return "de.thetaphi:forbiddenapis:${it.version}".toString()
68-
} else {
69-
// maven artifact pattern for gradle's plugin repositories.
70-
return "${it.pluginId}:${it.pluginId}.gradle.plugin:${it.version}".toString()
71-
}
72-
}
73-
}
74-
75-
dependencies {
76-
implementation gradleApi()
77-
implementation localGroovy()
78-
implementation deps.commons.codec
79-
implementation deps.randomizedtesting.runner
80-
implementation deps.zstd
81-
82-
implementation deps.flexmark.core
83-
implementation deps.flexmark.ext.abbreviation
84-
implementation deps.flexmark.ext.attributes
85-
implementation deps.flexmark.ext.autolink
86-
implementation deps.flexmark.ext.tables
87-
implementation deps.gjf
88-
implementation deps.jgit
89-
implementation deps.ecj
90-
91-
implementation plugin(deps.plugins.carrotsearch.buildopts)
92-
implementation plugin(deps.plugins.carrotsearch.dependencychecks)
93-
implementation plugin(deps.plugins.forbiddenapis)
94-
implementation plugin(deps.plugins.spotless)
95-
implementation plugin(deps.plugins.undercouch.download)
96-
implementation plugin(deps.plugins.errorprone)
97-
implementation plugin(deps.plugins.jacocolog)
98-
implementation plugin(deps.plugins.versionCatalogUpdate)
99-
}
60+
apply from: file("declare-dependencies.gradle")
10061

10162
def hasJavaFlightRecorder = ModuleLayer.boot().findModule('jdk.jfr').map {otherModule ->
10263
this.getClass().module.canRead(otherModule)
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to You under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
// These are dependencies on gradle plugins. This file is extracted
19+
// from the main build.gradle because it's reused in build-infra-shadow.
20+
21+
22+
// Convert a plugin dependency to a regular dependency so that we can
23+
// use [plugins] section in the top-level libs.versions.toml but
24+
// redeclare them as regular project dependencies.
25+
static Provider<String> plugin(Provider<PluginDependency> plugin) {
26+
return plugin.map {
27+
if (it.pluginId == "de.thetaphi.forbiddenapis") {
28+
// Uwe's forbiddenapis is on Maven Central, so don't remap coordinates.
29+
return "de.thetaphi:forbiddenapis:${it.version}".toString()
30+
} else {
31+
// maven artifact pattern for gradle's plugin repositories.
32+
return "${it.pluginId}:${it.pluginId}.gradle.plugin:${it.version}".toString()
33+
}
34+
}
35+
}
36+
37+
dependencies {
38+
implementation gradleApi()
39+
implementation localGroovy()
40+
41+
implementation deps.commons.codec
42+
implementation deps.randomizedtesting.runner
43+
implementation deps.zstd
44+
45+
implementation deps.flexmark.core
46+
implementation deps.flexmark.ext.abbreviation
47+
implementation deps.flexmark.ext.attributes
48+
implementation deps.flexmark.ext.autolink
49+
implementation deps.flexmark.ext.tables
50+
implementation deps.gjf
51+
implementation deps.jgit
52+
implementation deps.ecj
53+
implementation deps.errorprone
54+
55+
implementation plugin(deps.plugins.carrotsearch.buildopts)
56+
implementation plugin(deps.plugins.carrotsearch.dependencychecks)
57+
implementation plugin(deps.plugins.forbiddenapis)
58+
implementation plugin(deps.plugins.spotless)
59+
implementation plugin(deps.plugins.undercouch.download)
60+
implementation plugin(deps.plugins.errorprone)
61+
implementation plugin(deps.plugins.jacocolog)
62+
implementation plugin(deps.plugins.versionCatalogUpdate)
63+
}

build-tools/build-infra/src/main/groovy/lucene.documentation.gradle

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,6 @@ configure(rootProject) {
3636
}
3737
})
3838

39-
ext {
40-
luceneDocUrl = luceneJavadocUrl.getOrElse(null)
41-
}
42-
4339
def documentationTask = tasks.register("documentation", {
4440
group = 'documentation'
4541
description = 'Generate all documentation'

build-tools/build-infra/src/main/groovy/lucene.documentation.render-javadoc.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ allprojects {
116116
("https://junit.org/junit4/javadoc/${junitVersion}/".toString()): junitJavadocPackages
117117
]
118118

119-
luceneDocUrl = provider({ rootProject.luceneDocUrl })
119+
luceneDocUrl = project.rootProject.buildOptions.getOption('lucene.javadoc.url').asStringProvider()
120120

121121
// Set up custom doclet.
122122
dependsOn configurations.missingdoclet

0 commit comments

Comments
 (0)