问题
I'm using gradle 4.1 My project has five modules. After build I generate five jars in each module. My goal is to create a zip archive and upload it to artifactory server. I can only generate my zip deploy artifact with my jars only when build of other modules is complete. I see that it copies jars from libs directory, but I'm looking for a way to do this after the overall build of the project. I saw some examples with dependsOn, but it doesn't seem to be working. Here is what I have:
apply plugin: 'distribution'
distributions {
main {
baseName = 'b-deploy'
contents {
from { "b-model/build/libs/b-model-${version}.jar" }
from { "b-wsdl/build/libs/b-wsdl-${version}.jar" }
from { "b-common/build/libs/b-common-${version}.jar" }
from { "b-rest/build/libs/b-rest-${version}.jar" }
from { "b-soap/build/libs/b-soap-${version}.jar" }
}
}
}
回答1:
Create a custom configuration to hold all you deployables:
configurations {
deployable {
transitive = false
}
}
Gather everything you need in your ZIP in that configuration. Note how you can add third-party libraries here, if you need them:
dependencies {
deployable project(path: ':a')
deployable project(path: ':b')
deployable 'com.google.guava:guava:22.0'
}
Then, create a task for that ZIP:
task deployableZIP(type: Zip) {
dependsOn configurations.deployable
baseName = 'gradle-deploy'
destinationDir = buildDir
configurations.deployable.collect {
from it
}
}
Finally, configure publishing:
publishing {
publications {
main(MavenPublication) {
artifact source: deployableZIP, extension: 'zip'
}
}
}
Should do the trick.
回答2:
Maybe you could use finalizedBy?.
So in your example:
build.finalizedBy(distributions)
来源:https://stackoverflow.com/questions/46286348/run-gradle-task-after-project-is-built-with-distribution-plugin