0

Who facilitates, that any file from resources subdirectory from source set is copied to resources folder of build directory?

I have created simple Gradle project inside IntelliJ and have configured additional source root called demo:

enter image description here

build.gradle is follows:

group 'net.inthemoon.tests'
version '1.0-SNAPSHOT'

apply plugin: 'java'

sourceCompatibility = 1.5

repositories {
    mavenCentral()
}

dependencies {
    testCompile group: 'junit', name: 'junit', version: '4.11'
}

sourceSets {
    demo
}

Then I placed simple text files into rerources directories of both sets.

After that I noticed, that highlighted file (one from demo source set) appears only if I run build from IntelliJ. If I run build goal from Gradle, only second file (from main source set) appears.

How to configure gradle to process all files from all source sets?

Dims
  • 47,675
  • 117
  • 331
  • 600

1 Answers1

1

I don't use intellij so i can't tell you why it automatcally executes demoClasses to compile and copy the demo sourceSet but you can execute it and will see the resources as intellij would do it.

just add

build.dependsOn demoClasses

and it will do it on every build. To add them to your jar you have to add it as source like

jar {
    from sourceSets.demo.output
}

For a sourceset that depends on the main just add it's output

sourceSets {
    demo {
        compileClasspath += sourceSets.main.output
        runtimeClasspath += sourceSets.main.output
    }
}

And if you also need it's compile/runtime libs for demo compile just do

sourceSets {
    demo {
        compileClasspath += sourceSets.main.runtimeClasspath
        runtimeClasspath += sourceSets.main.runtimeClasspath
    }
}
Hillkorn
  • 633
  • 4
  • 12
  • After I add these lines, I got numerous errors about not finding symbols and packages, as if demo source set does not know about classes from main source set. – Dims Jun 13 '16 at 10:02
  • Yes that's right. I added the configs for your needs but there are already several examples about that topic how to add them see http://stackoverflow.com/questions/11581419/how-do-i-add-a-new-sourceset-to-gradle – Hillkorn Jun 13 '16 at 15:24