Skip to content

Apache Lucene open-source search software

Move away from project.javaexec (#15245)

Kaival Parikh53921093e689
diff --git a/build-tools/build-infra/src/main/groovy/lucene.regenerate.antlr.gradle b/build-tools/build-infra/src/main/groovy/lucene.regenerate.antlr.gradle
index 18dbceec3fd..b75d86c882b 100644
--- a/build-tools/build-infra/src/main/groovy/lucene.regenerate.antlr.gradle
+++ b/build-tools/build-infra/src/main/groovy/lucene.regenerate.antlr.gradle
@@ -15,6 +15,8 @@
* limitations under the License.
*/
+import org.apache.lucene.gradle.plugins.help.ExecOperationsProvider
+
configure(project(":lucene:expressions")) {
configurations {
antlr
@@ -49,8 +51,9 @@ configure(project(":lucene:expressions")) {
doFirst {
project.delete tempOutput
- project.javaexec {
- main = "org.antlr.v4.Tool"
+ def execOps = objects.newInstance(ExecOperationsProvider).execOperations
+ execOps.javaexec {
+ mainClass = "org.antlr.v4.Tool"
classpath = configurations.antlr
ignoreExitValue = false
diff --git a/build-tools/build-infra/src/main/groovy/lucene.regenerate.icu.gradle b/build-tools/build-infra/src/main/groovy/lucene.regenerate.icu.gradle
index 39446cd7567..107106b586c 100644
--- a/build-tools/build-infra/src/main/groovy/lucene.regenerate.icu.gradle
+++ b/build-tools/build-infra/src/main/groovy/lucene.regenerate.icu.gradle
@@ -17,6 +17,7 @@
import org.apache.tools.ant.taskdefs.condition.Os
import java.nio.file.Files
+import org.apache.lucene.gradle.plugins.help.ExecOperationsProvider
def resources = rootProject.file("gradle/regenerate/icu")
@@ -94,8 +95,9 @@ configure(project(":lucene:analysis:icu")) {
doFirst {
// all these steps must be done sequentially: it's a pipeline resulting in utr30.nrm
- project.javaexec {
- main = "org.apache.lucene.analysis.icu.GenerateUTR30DataFiles"
+ def execOps = objects.newInstance(ExecOperationsProvider).execOperations
+ execOps.javaexec {
+ mainClass = "org.apache.lucene.analysis.icu.GenerateUTR30DataFiles"
classpath = sourceSets.tools.runtimeClasspath
ignoreExitValue = false
@@ -144,8 +146,9 @@ configure(project(":lucene:analysis:icu")) {
outputs.files fileTree(dir: targetDir, include: "*.brk")
doFirst {
- project.javaexec {
- main = "org.apache.lucene.analysis.icu.RBBIRuleCompiler"
+ def execOps = objects.newInstance(ExecOperationsProvider).execOperations
+ execOps.javaexec {
+ mainClass = "org.apache.lucene.analysis.icu.RBBIRuleCompiler"
classpath = sourceSets.tools.runtimeClasspath
ignoreExitValue = false
@@ -269,8 +272,9 @@ configure(project(":lucene:analysis:common")) {
outputs.file outputFile
doFirst {
- project.javaexec {
- main "groovy.lang.GroovyShell"
+ def execOps = objects.newInstance(ExecOperationsProvider).execOperations
+ execOps.javaexec {
+ mainClass "groovy.lang.GroovyShell"
classpath icuConfig, groovyConfig
args = [
@@ -308,8 +312,9 @@ configure(project(":lucene:core")) {
outputs.file outputFile
doFirst {
- project.javaexec {
- main "groovy.lang.GroovyShell"
+ def execOps = objects.newInstance(ExecOperationsProvider).execOperations
+ execOps.javaexec {
+ mainClass "groovy.lang.GroovyShell"
classpath icuConfig, groovyConfig
args = [
diff --git a/build-tools/build-infra/src/main/groovy/lucene.regenerate.javacc.gradle b/build-tools/build-infra/src/main/groovy/lucene.regenerate.javacc.gradle
index 7ebdd6ad974..654d0b77951 100644
--- a/build-tools/build-infra/src/main/groovy/lucene.regenerate.javacc.gradle
+++ b/build-tools/build-infra/src/main/groovy/lucene.regenerate.javacc.gradle
@@ -16,7 +16,7 @@
*/
import java.nio.charset.Charset
-import java.util.function.Function
+import org.apache.lucene.gradle.plugins.help.ExecOperationsProvider
// This adds javacc generation support.
@@ -304,7 +304,8 @@ class JavaCCTask extends DefaultTask {
logger.lifecycle("Recompiling JavaCC: ${project.rootDir.relativePath(javaccFile)}")
def output = new ByteArrayOutputStream()
- def result = project.javaexec {
+ def execOps = project.objects.newInstance(ExecOperationsProvider).execOperations
+ execOps.javaexec {
classpath {
project.rootProject.configurations.javacc
}
@@ -313,7 +314,7 @@ class JavaCCTask extends DefaultTask {
standardOutput = output
errorOutput = output
- main = "org.javacc.parser.Main"
+ mainClass = "org.javacc.parser.Main"
args += [
"-OUTPUT_DIRECTORY=${tempDir}",
javaccFile
diff --git a/build-tools/build-infra/src/main/groovy/lucene.regenerate.jflex.gradle b/build-tools/build-infra/src/main/groovy/lucene.regenerate.jflex.gradle
index 82dd990de2b..9b93836ab2f 100644
--- a/build-tools/build-infra/src/main/groovy/lucene.regenerate.jflex.gradle
+++ b/build-tools/build-infra/src/main/groovy/lucene.regenerate.jflex.gradle
@@ -15,8 +15,8 @@
* limitations under the License.
*/
-import java.nio.file.Files
import org.apache.lucene.gradle.plugins.misc.QuietExec
+import org.apache.lucene.gradle.plugins.help.ExecOperationsProvider
// Add a top-level pseudo-task to which we will attach individual regenerate tasks.
@@ -80,8 +80,9 @@ configure(project(":lucene:analysis:common")) {
File tmpJflexMacro = File.createTempFile(jflexMacro.getName(), ".tmp", getTemporaryDir())
File tmpTldList = File.createTempFile(tldList.getName(), ".tmp", getTemporaryDir())
- project.javaexec {
- main = "org.apache.lucene.analysis.standard.GenerateJflexTLDMacros"
+ def execOps = objects.newInstance(ExecOperationsProvider).execOperations
+ execOps.javaexec {
+ mainClass = "org.apache.lucene.analysis.standard.GenerateJflexTLDMacros"
classpath = sourceSets.tools.runtimeClasspath
ignoreExitValue = false
@@ -261,12 +262,13 @@ class JFlexTask extends DefaultTask {
logger.lifecycle("Recompiling JFlex: ${project.rootDir.relativePath(jflexFile)}")
- project.javaexec {
+ def execOps = project.objects.newInstance(ExecOperationsProvider).execOperations
+ execOps.javaexec {
classpath {
project.rootProject.configurations.jflex
}
- main = "jflex.Main"
+ mainClass = "jflex.Main"
args += [
"-nobak",
"--quiet",
diff --git a/build-tools/build-infra/src/main/groovy/lucene.regenerate.kuromoji.gradle b/build-tools/build-infra/src/main/groovy/lucene.regenerate.kuromoji.gradle
index 263014c7661..048b40dae74 100644
--- a/build-tools/build-infra/src/main/groovy/lucene.regenerate.kuromoji.gradle
+++ b/build-tools/build-infra/src/main/groovy/lucene.regenerate.kuromoji.gradle
@@ -15,12 +15,14 @@
* limitations under the License.
*/
import de.undercouch.gradle.tasks.download.Download
+import org.apache.lucene.gradle.plugins.help.ExecOperationsProvider
// This downloads and compiles Kuromoji dictionaries.
def recompileDictionary(project, dictionaryName, Closure closure) {
- project.javaexec {
- main = "org.apache.lucene.analysis.ja.dict.DictionaryBuilder"
+ def execOps = objects.newInstance(ExecOperationsProvider).execOperations
+ execOps.javaexec {
+ mainClass = "org.apache.lucene.analysis.ja.dict.DictionaryBuilder"
classpath = project.sourceSets.main.runtimeClasspath
jvmArgs '-Xmx1G'
diff --git a/build-tools/build-infra/src/main/groovy/lucene.regenerate.nori.gradle b/build-tools/build-infra/src/main/groovy/lucene.regenerate.nori.gradle
index bd22b96ffaa..051d1aeaf8d 100644
--- a/build-tools/build-infra/src/main/groovy/lucene.regenerate.nori.gradle
+++ b/build-tools/build-infra/src/main/groovy/lucene.regenerate.nori.gradle
@@ -15,12 +15,14 @@
* limitations under the License.
*/
import de.undercouch.gradle.tasks.download.Download
+import org.apache.lucene.gradle.plugins.help.ExecOperationsProvider
// This downloads and compiles Nori dictionaries.
def recompileDictionary(project, dictionaryName, Closure closure) {
- project.javaexec {
- main = "org.apache.lucene.analysis.ko.dict.DictionaryBuilder"
+ def execOps = objects.newInstance(ExecOperationsProvider).execOperations
+ execOps.javaexec {
+ mainClass = "org.apache.lucene.analysis.ko.dict.DictionaryBuilder"
classpath = project.sourceSets.main.runtimeClasspath
jvmArgs '-Xmx1G'
diff --git a/build-tools/build-infra/src/main/java/org/apache/lucene/gradle/plugins/help/ExecOperationsProvider.java b/build-tools/build-infra/src/main/java/org/apache/lucene/gradle/plugins/help/ExecOperationsProvider.java
new file mode 100644
index 00000000000..b246a8a4a87
--- /dev/null
+++ b/build-tools/build-infra/src/main/java/org/apache/lucene/gradle/plugins/help/ExecOperationsProvider.java
@@ -0,0 +1,27 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.lucene.gradle.plugins.help;
+
+import javax.inject.Inject;
+import org.gradle.process.ExecOperations;
+
+// We need this for the new gradle configuration cache. I personally think it's awful.
+interface ExecOperationsProvider {
+ @Inject
+ ExecOperations getExecOperations();
+}
diff --git a/lucene/analysis/common/build.gradle b/lucene/analysis/common/build.gradle
index faa3a1db2b0..3b2921b3dfc 100644
--- a/lucene/analysis/common/build.gradle
+++ b/lucene/analysis/common/build.gradle
@@ -17,9 +17,8 @@
import com.carrotsearch.gradle.buildinfra.buildoptions.BuildOption
-
import java.nio.file.Files;
-
+import org.apache.lucene.gradle.plugins.help.ExecOperationsProvider
description = 'Analyzers for indexing content in different languages and domains'
@@ -55,13 +54,6 @@ def dictionaryProjects = [
]
]
-// We need this for the new gradle configuration cache. I personally think it's
-// awful.
-interface ExecOperationsProvider {
- @javax.inject.Inject
- ExecOperations getExecOperations()
-}
-
// Generate a set of tasks cloning the git repository of each project
// and setting it to the given reference (hash or named).
def cloningTasks = dictionaryProjects.collect { repoSpec ->
diff --git a/lucene/analysis/opennlp/build.gradle b/lucene/analysis/opennlp/build.gradle
index ef056b664bb..bac87054bc3 100644
--- a/lucene/analysis/opennlp/build.gradle
+++ b/lucene/analysis/opennlp/build.gradle
@@ -15,7 +15,7 @@
* limitations under the License.
*/
-
+import org.apache.lucene.gradle.plugins.help.ExecOperationsProvider
description = 'OpenNLP Library Integration'
@@ -51,7 +51,8 @@ tasks.register('trainTestModels') {
}
def trainModel(String command, String lang, String data, String model, List extraArgs = []) {
- javaexec {
+ def execOps = objects.newInstance(ExecOperationsProvider).execOperations
+ execOps.javaexec {
classpath = sourceSets.main.compileClasspath
mainClass = 'opennlp.tools.cmdline.CLI'
workingDir = testModelDataDir