Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get source code directory in Gradle plugin?

Tags:

gradle

I want to get the directory of Java files in a Groovy plugin.

For example, I have a Java file in a directory:

"/gradleProject/src/main/java/com/file.java"

How can I get:

"src/main/java"

In Maven there is Build.getSourceDirectory(), what is the equivalent in Gradle?

like image 202
Roni_s Avatar asked Jun 05 '17 18:06

Roni_s


1 Answers

Further to Rene's answer, the groovy DSL makes it easy to get the SourceSet

SourceSet mainSourceSet = project.sourceSets.main

In java this is a little bit more verbose

SourceSet mainSourceSet = project.getConvention().getPlugin(JavaPluginConvention.class).getSourceSets().getByName("main");
like image 167
lance-java Avatar answered Nov 15 '22 08:11

lance-java