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

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

问题描述

我们有一个多项目 gradle 设置,每个子项目都有一个 Java jar:

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

现在,因为我们正在创建一个 Java webstart 应用程序,我们需要对所有项目 jar 以及所有第三方库(依赖项)进行签名.

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

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

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.

这是我在根 build.gradle 中的方法:

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')
}

一起:

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

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

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.

也许我的方法是完全错误的.我该怎么做才能复制所有创建的 &将第三方 jar 文件放到一个文件夹中?

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

推荐答案

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

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 将第三方 jar 文件放入单个文件夹中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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