mercredi 20 mars 2019

Gradle test resources

I'm new to gradle, trying to set up an old project (which used ant). Project setup is fine, though rather complex because of some ugly requirements where different resources need to go multiple different places, with some needing to be filtered according to different properties files etc..

Anyway, I am now trying to set up testing. The problem is that the tests require a hibernate.properties file that is different to the one used in the main project. So, I added a reference to the relevant resource folder:

sourceSets {
    test {
        resources {
            srcDirs "${outputDir}/test/generated-src"
        }
    }
}

The hibernate.properties file for the main project is in:

sourceSets {
    main {
        resources {
            srcDirs "${outputDir}/generated-src"
        }
    }
}

(The reason they are not just in src/main/resources etc, is that they required some special handling before they can be used.)

Using "gradle test" works (probably by luck), because it uses the hibernate.properties from the test folder. But, running junit tests from Eclipse does not work, because in Eclipse the "${outputDir}/test/generated-src" folder gets added to the classpath AFTER the main one. So the tests find the main hibernate.properties, and fail...

I tried to mess around with reordering the classpath for Eclipse, but failed. A workaround is to manually change the order in Eclipse->project properties->Build path->Order and export, but I would like a proper solution.

I'm thinking this probably isn't an unknown problem, and there is probably a proper gradle solution to it?

Aucun commentaire:

Enregistrer un commentaire