Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Copy all created & third-party jars into a single folder with Gradle

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?

like image 967
Dominic Avatar asked Jul 21 '14 15:07

Dominic


People also ask

What is the copy All command?

Keyboard Command: Control (Ctrl) + C The COPY command is used for just that - it copies the text or image you have selected and stores is on your virtual clipboard, until it is overwritten by the next "cut" or "copy" command.

How do you copy all files once?

Step 1: Click on the first file to be selected. Step 2: Hold down Ctrl and click on all the files that you want to select additionally. Step 2: Press the Shift key and click on the last file. Step 3: You have now selected all files at once and can copy and move them.

How copy all files in Linux?

Copying Directories with cp Command To copy a directory, including all its files and subdirectories, use the -R or -r option. The command above creates the destination directory and recursively copy all files and subdirectories from the source to the destination directory.

How can I copy all files in a folder?

Copy and paste filesRight-click and pick Copy, or press Ctrl + C . Navigate to another folder, where you want to put the copy of the file. Click the menu button and pick Paste to finish copying the file, or press Ctrl + V . There will now be a copy of the file in the original folder and the other folder.


1 Answers

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])
like image 88
Opal Avatar answered Oct 26 '22 18:10

Opal