复制所有创建的&第三方使用Gradle将其与一个文件夹放入一个文件夹中 [英] Copy all created & third-party jars into a single folder with Gradle

查看:154
本文介绍了复制所有创建的&第三方使用Gradle将其与一个文件夹放入一个文件夹中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

   -  root-project $ b $我们有一个多项目gradle设置,每个子项目都有一个Java jar。 b | -sub-project-a 
| -sub-project-b
| -sub-project-c

现在,由于我们正在创建一个Java webstart应用程序,因此我们需要签署所有项目jar以及所有第三方库(依赖项)。



我现在的做法是将所有构建的子项目jar和所有第三方库复制到一个单独的文件夹中,并执行任务以对它们进行签名。但是我无法复制罐子。



这是我在root build.gradle中的做法:



<$ ($
from(build / libs)
into(
from configurations.runtime
from(build / libs)
into webstart / lib)
include('*。jar')
}



<

 任务符号全部(dependsOn:[copyFiles])<< {
新文件('webstart / signed')。mkdirs()
def libFiles = files {file('webstart / lib')。listFiles()}
...
}

然后我尝试执行gradle signAll。但是,我只能在webstart / lib文件夹中找到一个名为root项目名称的空jar。



也许我的方法是完全错误的。我需要做什么来复制所有创建的& thrid-party jar into a single folder?

解决方案

将这段代码添加到root build.gradle中,它应该可以正常工作:

  allprojects {
apply plugin:'java'
repositories {
mavenCentral()



任务copyJars(类型:Copy,dependsOn:subprojects.jar){
from(subprojects.jar)
into project.file( 'dest')
}

任务copyDeps(type:Copy){
from(subprojects.configurations.runtime)
into project.file('dest / lib ')
}

任务copyFiles(dependsOn:[copyJars,copyDeps])


we have a multi-project gradle setup with one Java jar for each subproject:

- root-project
  |-sub-project-a
  |-sub-project-b
  |-sub-project-c

Now, because we are creating a Java webstart application, we need to sign all project jars as well as all third-party libraries (dependencies).

My approach was now to copy all built subproject jars and all third-party libraries into a seperate folder and execute a task for signing them. However I am not able to copy the jars.

This was my approach in the root build.gradle:

task copyFiles(type: Copy, dependsOn: subprojects.jar) {
    from configurations.runtime
    from("build/libs")
    into("webstart/lib")
    include('*.jar')
}

together with:

task signAll(dependsOn: [copyFiles]) << {
    new File('webstart/signed').mkdirs()
    def libFiles = files { file('webstart/lib').listFiles() }
    ...
}

Then I tried to execute gradle signAll. However, I can only find an empty jar with the name of the root project in the webstart/lib folder.

Maybe my approach is completely wrong. What do I have to do to copy all created & thrid-party jars into a single folder?

解决方案

Add this piece of code to root build.gradle and it should work fine:

allprojects {
    apply plugin: 'java'
    repositories {
        mavenCentral()
    }
}

task copyJars(type: Copy, dependsOn: subprojects.jar) {
    from(subprojects.jar) 
    into project.file('dest')
}

task copyDeps(type: Copy) {
    from(subprojects.configurations.runtime) 
    into project.file('dest/lib')
}

task copyFiles(dependsOn: [copyJars, copyDeps])

这篇关于复制所有创建的&amp;第三方使用Gradle将其与一个文件夹放入一个文件夹中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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