IDEA 8.1.2 / Maven: Test resources keep getting overwritten

Hey all,

I'm using IDEA 8.1.2 and have noticed that the way IDEA copies files over prior to tests running has changed, and is now consistently breaking my tests when running through the IDE.  Breifly, here is what I am doing.

  • Test looks for a file on the classpath, lets call it "foo.properties".  In the mvn2 source tree, this is in /src/test/resources and is copied to /target/test-classes - nothing special.
  • foo.properties contains template text which is replaced by maven in the process-test-resources phase, before copying into the target directory
  • IDEA's classpath is configured by the maven plugin, and I presume it looks at target/test-classes - NOT at src/test/resources (or it would never work)


To successfully run this test:

  • The files in test/resources must have been filtered and copied (by previously running mvn process-test-resources or another phase that executes it)
  • I can then use shift-ctrl-F10 to execute the test from the IDE, and since the classpath is configured to target/test-classes it picks up the previosuly filtered properties file and all is good


This approach works fine in IDEA 8.1.0, however, not in 8.1.2.  When running the test from the IDE, instead of it using the "foo.properties" in target/test-classes as-is, IDEA is copying the template foo.properties from src/test/reources and blowing away whatever was there, before running the test, each time the test is run.  That causes the test to fail because the it picks up the unfiltered (wrong) property values and I've been unable to find a way to stop IDEA doing that.

Is this a bug, or am I doing something wrong?   I've reverted back to 8.1 for now to get going again.  Thanks for any advice.

Cheers,
Jason

8 comments
Comment actions Permalink

I have quite similar issue. Suppose that I have defined a profile in the settings.xml file. When I click 'process-resource' my profile isn't turn on and properties file isn't filled with appropriate properties. The first solution could be fix for this OLD issue:

http://www.jetbrains.net/jira/browse/IDEADEV-23952

The second is that you could define configuration for this maven goal and give him proper profile. Than you can define the configuration for the test and run it WITHOUT MAKE, because make will override the properties file to default version...

I hope this is some solution for your problem ;-)

0
Comment actions Permalink

Hi, Jason,

IDEA Make is now able to filter resources according to the settings in your pom file.
If it doesn't do so, it is probably a bug or a configuration problem.
Can you please attach a sample pom file?

Thanks,
Anton Makeev

0
Comment actions Permalink

Hi Anton,
maybe you are right, but if the profile with i.e. configuration to database is defined in the settings.xml, you cannot tick it in IDEA profiles view and after IDEA make the properties file will be overwritten by default properties like {db.name} etc.

0
Comment actions Permalink

OK, I'll check this scenario.

Thanks,
Anton Makeev

0
Comment actions Permalink

Great, thanks.

I think fixing this issue:
http://www.jetbrains.net/jira/browse/IDEADEV-23952
will resolve the problem, cause then you can tick profile even from settings.xml and every maven goal launched from Maven project view will have this profile turn on.

0
Comment actions Permalink

Hi,

Yes, the properties come from the POM, and are contained in a profile (not settings.xml but probably the same result).  The default profile has no properties defined, so the properties file would not get filtered if profiles were not being used and so I would get the result I'm seeing.

I tried ticking the appropriate profile in the Maven view but didn't have any joy there either.  I'll try and produce a simple POM that demonstrates the problem tomorrow, unless I get it working (11:30pm here now, and I'm too tired to code)

Cheers,
Jason

0
Comment actions Permalink

Resolved in Maia 10322. Thanks!

Update:
Something strange. When my pom files was broken I was able to see profiles from settings.xml. When they are fixed, these profiles disappear.

0
Comment actions Permalink

This problem is fixed too. Please try the next Maia eap.

Thanks,
Anton Makeev

0

Please sign in to leave a comment.