Alternative to `libsDir`

(Niko Strijbol) #1

We recently updated to a newer version of Gradle, which caused following warnings:

The libsDir method has been deprecated.

Anybody know what the alternative is? I have found nothing in the documentation, nothing in de source code, nothing in the commit that deprecated it.

I have searched the forums for similar messages, but the only semi-relevant post has no answer either.


(uklance) #2

Please include the relevant snippets from your build.gradle so we can understand what you’re trying to achieve


(Niko Strijbol) #3

So I basically have a Spring Boot server, which will submit jobs to a Spark cluster. To run these jobs on Spark, I must somehow get the jar with the job code (in Java) to the cluster. To avoid doing things manually, I thought it would be nice if my Spring application could upload the jar on server start.

Therefor I’m trying to add the job jar as a resource to my Spring App. The project structure is as follows:

├── spark (small pure Java module with Spark job code)
├── ... other modules
└── rest (Spring Boot server)

Relevant snippet from Gradle (copies fat jar from subproject to main project resources):

gradle.projectsEvaluated {

	task addSparkJobs(type: Copy, dependsOn: ":spark:shadowJar") {
		description "Ensures job jar for Spark is present"
		from project(':spark').libsDir
		include 'spark-*-all.jar'
		rename '.*', 'spark-all.jar'
		into "${sourceSets.main.output.resourcesDir.toString()}/jobs/"

	jar.dependsOn addSparkJobs

(uklance) #4

I get the feeling you could replace

from project(':spark').libsDir
include 'spark-*-all.jar'


from project(':spark').tasks['shadowJar'] 

Most of Gradle’s file based task methods (eg Copy.from(…)) accept Object for a file which can be many different things, including a Task instance

See Project.files(Object…)

A Task . Converted to the task’s output files. The task is executed if the file collection is used as an input to another task.

I’m guessing you could also replace

gradle.projectsEvaluated {...} 


evaluationDependsOn ':spark' 

See Project.evaluationDependsOn(…)


(Niko Strijbol) #5

Thanks a lot, this works exactly as I want it to!