diff --git a/examples/java/build.gradle b/examples/java/build.gradle index e10d4fd6b1d6..98763e911134 100644 --- a/examples/java/build.gradle +++ b/examples/java/build.gradle @@ -41,9 +41,14 @@ artifact includes all Apache Beam Java SDK examples.""" * for details. */ def preCommitRunners = ["directRunner", "flinkRunner", "sparkRunner"] +// The following runners have configuration created but not added to preCommit +def nonPreCommitRunners = ["dataflowRunner", "prismRunner"] for (String runner : preCommitRunners) { configurations.create(runner + "PreCommit") } +for (String runner: nonPreCommitRunners) { + configurations.create(runner + "PreCommit") +} configurations.sparkRunnerPreCommit { // Ban certain dependencies to prevent a StackOverflow within Spark // because JUL -> SLF4J -> JUL, and similarly JDK14 -> SLF4J -> JDK14 @@ -123,6 +128,10 @@ dependencies { flinkRunnerPreCommit project(":runners:flink:${project.ext.latestFlinkVersion}") sparkRunnerPreCommit project(":runners:spark:3") sparkRunnerPreCommit project(":sdks:java:io:hadoop-file-system") + dataflowRunnerPreCommit project(":runners:google-cloud-dataflow-java") + dataflowRunnerPreCommit project(":runners:google-cloud-dataflow-java:worker") // v2 worker + dataflowRunnerPreCommit project(":sdks:java:harness") // v2 worker + prismRunnerPreCommit project(":runners:prism:java") // Add dependency if requested on command line for runner if (project.hasProperty("runnerDependency")) { @@ -167,11 +176,37 @@ task preCommit() { } } +/* + * A convenient task to run individual example directly on Beam repo. + * + * Usage: + * ./gradlew :examples:java:execute -PmainClass=org.apache.beam.examples.`\ + * -Pexec.args="runner=[DataflowRunner|DirectRunner|FlinkRunner|SparkRunner|PrismRunner] \ + * " + */ tasks.create(name:"execute", type:JavaExec) { - main = project.hasProperty("mainClass") ? project.getProperty("mainClass") : "NONE" - classpath = sourceSets.main.runtimeClasspath + mainClass = project.hasProperty("mainClass") ? project.getProperty("mainClass") : "NONE" + def execArgs = project.findProperty("exec.args") + String runner + if (execArgs) { + // configure runner dependency from args + def runnerPattern = /runner[ =]([A-Za-z]+)/ + def matcher = execArgs =~ runnerPattern + if (matcher) { + runner = matcher[0][1] + runner = runner.substring(0, 1).toLowerCase() + runner.substring(1); + if (!(runner in (preCommitRunners + nonPreCommitRunners))) { + throw new GradleException("Unsupported runner: " + runner) + } + } + } + if (runner) { + classpath = sourceSets.main.runtimeClasspath + configurations."${runner}PreCommit" + } else { + classpath = sourceSets.main.runtimeClasspath + } systemProperties System.getProperties() - args project.hasProperty("exec.args") ? project.getProperty("exec.args").split() : [] + args execArgs ? execArgs.split() : [] } // Run this task to validate the Java environment setup for contributors