139.223 No copy test resources

I have resource files (xml, sql) in my source directories. IDEA copies
those when I do a build.

I also have resource files in my test source directory. IDEA does not
copy them. Why is that?

Thank you,

Donald

14 comments
Comment actions Permalink

Resource files under test source directory should go to separate test output path, not into production output path. Do you mean reasources are not copied into _test output_ path?

Regards,
Alexander.

0
Comment actions Permalink

You are correct, they should go into the test output path.

They are not.

This is a problem.

On 11/5/14 4:56 AM, Alexander Chernikov wrote:

Resource files under test source directory should go to separate test output path, not into production output path. Do you mean reasources are not copied into test output path?


0
Comment actions Permalink

Sorry, can't reproduce by now.

I expect, Settings dialog / Compiler / "Resource patterns" are correct?

Maybe you can attach a sample project to show the problem?

Regards,
Alexander.

0
Comment actions Permalink

I have a similar problem.

I've defined a test and an integration-test folder. Since IntelliJ 14 it copies only the resource files from test into the build folder, but the resources from integration-test are missing.

Best

Max

0
Comment actions Permalink

Is there any difference in IDEA settings for these two directories? Some difference in their appearance in Project tree view, or different settings in Project Strcuture dialog?

Thank you,
Alexander.

0
Comment actions Permalink

Afaik everything is the same. This has worked in IntelliJ 13 without a flaw, I just changed the IDE ?:|

I made a screenshot:

Screen Shot 2014-11-26 at 09.14.01.png

Best

Max

P.S.

Everything works fine if I run the test with gradle on the command line

0
Comment actions Permalink

Thank you.

Sorry, still can't reproduce. Maybe some gradle-specific. Will show this case to colleagues, maybe they'll get some idea.

Regards,
Alexander.

0
Comment actions Permalink

Max, there were changes in that area https://youtrack.jetbrains.com/issue/IDEA-126986#comment=27-764027

Please check this issue: https://youtrack.jetbrains.com/issue/IDEA-91952. Does it describe your problem?

Thank you.

0
Comment actions Permalink

Hi Alexander,

I've seen some stuff going on about this topic, but at this point I don't really have a clue what to do.
So I assembled a demo project with a failing test to reproduce the behavior.

Btw. I've seen that this is about EAP, but I'm using 14.0.1 139.225 - Sorry for using the wrong thread :)

Best

Max



Attachment(s):
test-resources-demo.zip
0
Comment actions Permalink

Max, if you run tests as JUnit, IDEA's Make is executed, but not Gradle's :build task. And Make is not aware of the custom behavior you specified in build script, that's why resources are not copied.

If you run Gradle :test task, recources are not copied either, because

    integrationTest.shouldRunAfter test


doesn't force :integrationTest to run after :test, it just specifies task ordering in case both tasks are executed.
Try to change the above line to

    test.dependsOn integrationTest


Thus you'll get the expected behavior.
1.png
Hope I've clarified your question.

Good luck :)
Victoria

0
Comment actions Permalink

Hi Victoria,

the intention was that test should not depend on integrationTest.

I'm curious why this worked with IDEA 13 and is not working anymore with IDEA 14 with the same Gradle config.

Best

Max

0
Comment actions Permalink

inheritOutputDirs = true seems to set the IDEA output dir correct, but doesn't help with the integration test resource when running the integration test as a junit test within IDEA.

Best

Max

0
Comment actions Permalink

Hi Max,

You know, gradle supports multiple source sets(with different classpath) per one project.
But, unfortunately, the information about custom source sets does not exposed by gradle tooling api which IDEA uses to get project information.
You can find related gradle issue at https://issues.gradle.org/browse/GRADLE-2680

Using some heuristic, IDEA 13 are able to resolve directories cofigured by custom source set as source/resources or test-sources/test-resources directories.
That's why it works for simple cases. But actually it was a workaround, I think IDEA should imports custom source sets as a separate IDEA modules to be able to configure right classpaths.
This will be addressed in v14.1

Since v14 IDEA gradle integration performs resources compilation based on configuration imported from gradle to support resource filtering, inclusion/exclusion, rename etc.
But, as I wrote above, IDEA still can not work properly with custom source sets and can use only built-in ("main" and "test") gradle source sets configuration.

So, if you want to have "src/integration-test/resources" in test classpath in IDEA you could add the following code:

sourceSets {
    test {
        resources.srcDirs += [file('src/integration-test/resources')]
    }
}


But be careful, in this case, you need to rename src/integration-test/resources/application-test.properties to avoid file name clashes, otherwise application-test.properties comes from different folders (src/integration-test/resources or src/test/resources) will overwrite each other.

0
Comment actions Permalink

Hi Vladislav,

thanks for your explanation, I got it now :)

Looking forward for IDEA 14.1 then.. (maybe I"ll apply your suggested workaround until it's ready)

Best

Max

0

Please sign in to leave a comment.