From 71b70cf8e55d6a81f372ceb75ad7932c39f68d19 Mon Sep 17 00:00:00 2001 From: rlee287 Date: Tue, 25 Aug 2020 17:11:09 -0700 Subject: [PATCH] #2219 Copy Jars into lib folder during plugin build automatically --- GhidraBuild/Skeleton/buildTemplate.gradle | 26 +++++++++++++++++++++++ GhidraBuild/Skeleton/lib/README.txt | 4 ++-- 2 files changed, 28 insertions(+), 2 deletions(-) diff --git a/GhidraBuild/Skeleton/buildTemplate.gradle b/GhidraBuild/Skeleton/buildTemplate.gradle index 7bf7fc7579..6efe651bc4 100644 --- a/GhidraBuild/Skeleton/buildTemplate.gradle +++ b/GhidraBuild/Skeleton/buildTemplate.gradle @@ -46,3 +46,29 @@ else { throw new GradleException("GHIDRA_INSTALL_DIR is not defined!") } //----------------------END "DO NOT MODIFY" SECTION------------------------------- + +// Include the code below if you want dependency jars to be automatically managed + +task copyDependencies(type: Copy) { + from configurations.default + into "lib" + exclude {fileTreeElement -> + def fileAbsPath = fileTreeElement.getFile().getCanonicalFile().toPath() + // Avoid including Ghidra Jars in lib folder... + def isGhidraJar = fileAbsPath.startsWith(ghidraInstallDir) + // ...and jars already in the destination location + def destLibDir = project.file("lib").getCanonicalFile().toPath() + def isFromDest = fileAbsPath.startsWith(destLibDir) + return isGhidraJar || isFromDest + } +} + +task cleanDependencyJars(type: Delete) { + delete fileTree("lib").matching { + include "**/*.jar" + } +} + +tasks.buildExtension.dependsOn(copyDependencies) +tasks.copyDependencies.dependsOn(cleanDependencyJars) +tasks.clean.dependsOn(cleanDependencyJars) diff --git a/GhidraBuild/Skeleton/lib/README.txt b/GhidraBuild/Skeleton/lib/README.txt index 224d94f8ca..b192e0177e 100644 --- a/GhidraBuild/Skeleton/lib/README.txt +++ b/GhidraBuild/Skeleton/lib/README.txt @@ -1,3 +1,3 @@ The "lib" directory is intended to hold Jar files which this module -is dependent upon. This directory may be eliminated from a specific -module if no other Jar files are needed. +is dependent upon. If you use the copyDependencies task, this directory +is automatically managed by Gradle and should not be modified.