1

I have an android gradle project and java gradle project as its dependency. The second one have separated unit test classes. It contains also resources placed in src/main/resources. Problem is that resources are not being copied to test build directory.

I've found that topic: http://forums.gradle.org/gradle/topics/resources_from_src_main_resources_not_included_for_test and adding the snippet from one before last post causes that resources are added and tests are working fine but building android APK fails due to duplicate classes. Can sourceSets be altered conditionally (only for test) or maybe there is a better way to include resources in tests?

This is mentioned snippet: sourceSets { main { output.resourcesDir = "build/classes/main" } }

koral
  • 2,513
  • 1
  • 32
  • 41
  • "Problem is that resources are not being copied to test build directory." What exact problem are you trying to solve here? Main resources *are* put on the test execution class path. – Peter Niederwieser Jun 25 '14 at 11:16
  • Problem is that resources are not found when I run test without mentioned snippet. To be clear: there is a file at `/src/main/resources//`. – koral Jun 25 '14 at 11:24
  • What resources are we talking about, and how exactly do they get loaded? This should work fine except in a few rare cases (e.g. JPA). – Peter Niederwieser Jun 25 '14 at 11:31
  • It is a text file `/src/main/resources//error_index.properties` it is loaded in the following way: `String propertiesFileName = "package_name>/error_index.properties";` `ClassLoader cld = ResponseErrorHandler.class.getClassLoader();` `InputStream instr = cld.getResourceAsStream(propertiesFileName);` Is it incorrect way? Project was initially created as java maven project using netbeans. – koral Jun 25 '14 at 12:05
  • 1
    Can't say from here why reconfiguring `sourceSets.main.output.resourcesDir` would make a difference in this case. In a pure Java project, it shouldn't. Perhaps try to set `jar.duplicatesStrategy = DuplicatesStrategy.EXCLUDE`. – Peter Niederwieser Jun 25 '14 at 12:09
  • Resources are generated using annotation processor fired by `querydsl-apt`. This is a configuration: task generateQueryDSL(type: JavaCompile, group: 'build') { source = sourceSets.main.java classpath = configurations.compile + configurations.querydslapt options.compilerArgs = [ "-proc:only", "-processor", " .ApiErrorAnnotationProcessor" ] destinationDir = sourceSets.main.resources.srcDirs.iterator().next() } – koral Jun 25 '14 at 12:19
  • With `jar.duplicatesStrategy = DuplicatesStrategy.EXCLUDE` it works. However this is so complicated solution. Maybe `querydsl-apt` is causing this problem? The rest of lines related to it: configurations { querydslapt } compileJava { dependsOn generateQueryDSL source generateQueryDSL.destinationDir } – koral Jun 25 '14 at 18:30

0 Answers0