-
-
Save facewindu/70a91a63e563a66f9809 to your computer and use it in GitHub Desktop.
SSCCE finalizedBy Gradle 2.3 / 2.4
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
apply plugin: MyPlugin | |
apply plugin: 'java' | |
//configure in the build script the publication | |
publishing { | |
publications{ | |
ivy(IvyPublication){ organisation 'foo' } | |
} | |
} | |
class MyPlugin implements Plugin<Project> { | |
void apply(Project project) { | |
//apply ivy publish plugin | |
project.pluginManager.apply(IvyPublishPlugin) | |
// add repo to project repos | |
project.repositories { ivy { url "$project.projectDir/ivyRepo" } } | |
//add all project repo to ivy publish repos | |
project.repositories.all { repo -> | |
if(repo instanceof IvyArtifactRepository){ | |
project.getExtensions().configure(PublishingExtension, new org.gradle.api.internal.ClosureBackedAction<PublishingExtension>({ repositories.add(repo) })) | |
} | |
} | |
//create a custom task | |
project.tasks.create('customTask', CustomTask) | |
} | |
@RuleSource | |
static class Rule { | |
@Finalize | |
public void addFinalizeOnCustomTask(org.gradle.api.tasks.TaskContainer tasks){ | |
tasks.withType(CustomTask).each {myTask -> | |
println myTask | |
tasks.withType(org.gradle.api.publish.ivy.tasks.PublishToIvyRepository).each{ | |
println it | |
myTask.finalizedBy it | |
} | |
} | |
} | |
} | |
} | |
class CustomTask extends org.gradle.api.DefaultTask{} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
apply plugin: MyPlugin | |
apply plugin: 'java' | |
//configure in the build script the publication | |
publishing { | |
publications{ | |
ivy(IvyPublication){ organisation 'foo' } | |
} | |
} | |
class MyPlugin implements Plugin<Project> { | |
void apply(Project project) { | |
//apply ivy publish plugin | |
project.pluginManager.apply(IvyPublishPlugin) | |
// add repo to project repos | |
project.repositories { ivy { url "$project.projectDir/ivyRepo" } } | |
//add all project repo to ivy publish repos | |
project.repositories.all { repo -> | |
if(repo instanceof IvyArtifactRepository){ | |
project.getExtensions().configure(PublishingExtension, new org.gradle.api.internal.ClosureBackedAction<PublishingExtension>({ repositories.add(repo) })) | |
} | |
} | |
//create a custom task | |
project.tasks.create('customTask', CustomTask) | |
} | |
static class Rule extends RuleSource{ | |
@Finalize | |
public void addFinalizeOnCustomTask(org.gradle.api.tasks.TaskContainer tasks){ | |
tasks.withType(CustomTask).each {myTask -> | |
println myTask | |
tasks.withType(org.gradle.api.publish.ivy.tasks.PublishToIvyRepository).each{ | |
println it | |
myTask.finalizedBy it | |
} | |
} | |
} | |
} | |
} | |
class CustomTask extends org.gradle.api.DefaultTask{} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
C:\Francois\workspaceLuna\GradleConsumer>gradlew clean customTask | |
task ':customTask' | |
task ':publishIvyPublicationToIvyRepository' | |
:clean UP-TO-DATE | |
:customTask UP-TO-DATE | |
:generateDescriptorFileForIvyPublication | |
:publishIvyPublicationToIvyRepository | |
BUILD SUCCESSFUL |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
C:\Francois\workspaceLuna\GradleConsumer>gradlew clean customTask | |
task ':customTask' | |
:clean | |
:customTask UP-TO-DATE | |
BUILD SUCCESSFUL |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment