在使用分发插件构建项目后运行gradle任务 [英] Run gradle task after project is built with distribution plugin

查看:168
本文介绍了在使用分发插件构建项目后运行gradle任务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用gradle 4.1
我的项目有五个模块。构建完成后,我会在每个模块中生成五个罐子。
我的目标是创建一个zip存档并将其上传到artifactory服务器。
只有在完成其他模块的构建时,我才能用我的罐子生成我的zip部署工件。我看到它从libs目录中复制jar,但是我正在寻找在项目的整体构建之后执行此操作的方法。我看到一些与dependsOn的例子,但它似乎并没有工作。
这是我的:

pre $ 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}
从{b-rest / build / libs / b-rest - $ {version} .jar}
from {b-soap / build / libs / b-soap- $ {version} .jar}
}
}
}




 配置{$ b} 

创建一个自定义配置来保存所有可部署对象。 $ b可部署{
transitive = false
}
}

在该配置中收集ZIP中所需的所有内容。注意如何在这里添加第三方库,如果你需要它们的话:

 依赖关系{
可部署项目:':a')
可部署项目(路径:':b')
可部署'com.google.guava:guava:22.0'
}


  task deployableZIP(type:Zip){
dependsOn configurations.deployable

aseName ='gradle-deploy'
destinationDir = buildDir

配置.deployable.collect {
from it
}
}

最后,配置发布:

  publishing {
publications {
main(MavenPublication){
工件来源:deployableZIP,扩展名:'zip'
}
}
}

应该这样做。


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" }
     }
   }
 }

解决方案

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.

这篇关于在使用分发插件构建项目后运行gradle任务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆