Nutel
Nutel

Reputation: 2294

Read gradle paths from project

Is there any way to access Gradle groovy plugin sourceSets dirs from my Groovy project built by Gradle? I am looking for default gradle src and resources directories.

I need it to avoid hardcoding a resources directory in my project but use the default Groovy plugin resource directory (resources/main).

Upvotes: 1

Views: 1408

Answers (2)

Rene Groeschke
Rene Groeschke

Reputation: 28653

You shouldn't mix up your production code with your test sources and your test resources. I would suggest the following layout (the default of the groovy plugin) of your src directories in your project:

  • groovy production code in "src/main/groovy"
  • unit tests written in java or groovy in "src/test/groovy" *.groovy resources for testing your DSL in "src/test/resources"

Now you can reference the .groovy dsl test files from your tests via

URL url = this.getClass().getResource("/testDsl.groovy");
File testDslFile = new File(url.getFile()); 

Upvotes: 1

Rene Groeschke
Rene Groeschke

Reputation: 28653

Can you explain the use case for that? within your gradle build you can access the groovy sourceSets dirs introduced by Gradles groovy plugin like this:

apply plugin:'groovy'

task printGroovySourceDirs << {
    sourceSets.main.groovy.srcDirs.each{
        println it.absolutePath
    }
}

Upvotes: 1

Related Questions