Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 38 additions & 3 deletions examples/java/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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")) {
Expand Down Expand Up @@ -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.<ClassName>`\
* -Pexec.args="runner=[DataflowRunner|DirectRunner|FlinkRunner|SparkRunner|PrismRunner] \
* <pipeline options>"
*/
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
Expand Down
Loading