Skip to content

Commit

Permalink
Fix sourceJar task dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
Abacn committed Oct 9, 2023
1 parent 2bbb348 commit 708fbf1
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2395,7 +2395,20 @@ class BeamModulePlugin implements Plugin<Project> {

// TODO: Decide whether this should be inlined into the one project that relies on it
// or be left here.
project.ext.applyAvroNature = { project.apply plugin: "com.commercehub.gradle.plugin.avro" }
project.ext.applyAvroNature = {
project.apply plugin: "com.commercehub.gradle.plugin.avro"

// add dependency BeamModulePlugin defined custom tasks
// they are defined only when certain flags are provided (e.g. -Prelease; -Ppublishing, etc)
def sourcesJar = project.tasks.findByName('sourcesJar')
if (sourcesJar != null) {
sourcesJar.dependsOn project.tasks.getByName('generateAvroJava')
}
def testSourcesJar = project.tasks.findByName('testSourcesJar')
if (testSourcesJar != null) {
testSourcesJar.dependsOn project.tasks.getByName('generateTestAvroJava')
}
}

project.ext.applyAntlrNature = {
project.apply plugin: 'antlr'
Expand All @@ -2406,6 +2419,17 @@ class BeamModulePlugin implements Plugin<Project> {
generatedSourceDirs += project.generateTestGrammarSource.outputDirectory
}
}

// add dependency BeamModulePlugin defined custom tasks
// they are defined only when certain flags are provided (e.g. -Prelease; -Ppublishing, etc)
def sourcesJar = project.tasks.findByName('sourcesJar')
if (sourcesJar != null) {
sourcesJar.mustRunAfter project.tasks.getByName('generateGrammarSource')
}
def testSourcesJar = project.tasks.findByName('testSourcesJar')
if (testSourcesJar != null) {
testSourcesJar.dependsOn project.tasks.getByName('generateTestGrammarSource')
}
}

// Creates a task to run the quickstart for a runner.
Expand Down
23 changes: 19 additions & 4 deletions runners/flink/flink_runner.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -46,36 +46,51 @@ evaluationDependsOn(":examples:java")
/*
* Copy & merge source overrides into build directory.
*/
def sourceOverridesBase = "${project.buildDir}/source-overrides/src"
def sourceOverridesBase = project.layout.buildDirectory.dir('source-overrides/src')

def copySourceOverrides = tasks.register('copySourceOverrides', Copy) {
it.from main_source_overrides
it.into "${sourceOverridesBase}/main/java"
it.duplicatesStrategy DuplicatesStrategy.INCLUDE
}
compileJava.dependsOn copySourceOverrides

def copyResourcesOverrides = tasks.register('copyResourcesOverrides', Copy) {
it.from main_resources_overrides
it.into "${sourceOverridesBase}/main/resources"
it.duplicatesStrategy DuplicatesStrategy.INCLUDE
}
processResources.dependsOn copyResourcesOverrides

def copyTestSourceOverrides = tasks.register('copyTestSourceOverrides', Copy) {
it.from test_source_overrides
it.into "${sourceOverridesBase}/test/java"
it.duplicatesStrategy DuplicatesStrategy.INCLUDE
}
compileTestJava.dependsOn copyTestSourceOverrides

def copyTestResourcesOverrides = tasks.register('copyTestResourcesOverrides', Copy) {
it.from test_resources_overrides
it.into "${sourceOverridesBase}/test/resources"
it.duplicatesStrategy DuplicatesStrategy.INCLUDE
}

// add dependency to gradle Java plugin defined tasks
compileJava.dependsOn copySourceOverrides
processResources.dependsOn copyResourcesOverrides
compileTestJava.dependsOn copyTestSourceOverrides
processTestResources.dependsOn copyTestResourcesOverrides

// add dependency BeamModulePlugin defined custom tasks
// they are defined only when certain flags are provided (e.g. -Prelease; -Ppublishing, etc)
def sourcesJar = project.tasks.findByName('sourcesJar')
if (sourcesJar != null) {
sourcesJar.dependsOn copySourceOverrides
sourcesJar.dependsOn copyResourcesOverrides
}
def testSourcesJar = project.tasks.findByName('testSourcesJar')
if (testSourcesJar != null) {
testSourcesJar.dependsOn copyTestSourceOverrides
testSourcesJar.dependsOn copyTestResourcesOverrides
}

/*
* We have to explicitly set all directories here to make sure each
* version of Flink has the correct overrides set.
Expand Down
7 changes: 7 additions & 0 deletions sdks/java/maven-archetypes/examples/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,13 @@ task generateSources(type: Exec) {
commandLine './generate-sources.sh'
}

// add dependency BeamModulePlugin defined custom tasks
// they are defined only when certain flags are provided (e.g. -Prelease; -Ppublishing, etc)
def sourcesJar = project.tasks.findByName('sourcesJar')
if (sourcesJar != null) {
sourcesJar.dependsOn generateSources
}

sourceSets {
main {
output.dir('src', builtBy: 'generateSources')
Expand Down
6 changes: 6 additions & 0 deletions sdks/java/maven-archetypes/gcp-bom-examples/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,12 @@ task generateSources(type: Exec) {
environment "HERE", "."
commandLine '../examples/generate-sources.sh'
}
// add dependency BeamModulePlugin defined custom tasks
// they are defined only when certain flags are provided (e.g. -Prelease; -Ppublishing, etc)
def sourcesJar = project.tasks.findByName('sourcesJar')
if (sourcesJar != null) {
sourcesJar.dependsOn generateSources
}

sourceSets {
main {
Expand Down

0 comments on commit 708fbf1

Please sign in to comment.