This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

Bug 212052 - 'Test File' action cleans dependent projects
Summary: 'Test File' action cleans dependent projects
Status: RESOLVED INCOMPLETE
Alias: None
Product: projects
Classification: Unclassified
Component: Maven (show other bugs)
Version: 7.1.2
Hardware: PC Windows XP
: P2 normal (vote)
Assignee: Milos Kleint
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2012-05-04 05:51 UTC by puppala
Modified: 2012-06-01 07:07 UTC (History)
2 users (show)

See Also:
Issue Type: DEFECT
Exception Reporter:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description puppala 2012-05-04 05:51:56 UTC
I have a Maven project with some JUnit test classes in it. The project has dependencies (both normal & test), which NetBeans recognizes as yet another Maven projects. This has the effect, that in the classpath of the test run, these dependencies will show as paths to their build directory (...\target\classes), NOT as jar artifacts from local Maven repository.

When I run a single test class ('Test File' action), IDE/Maven seems to clean those dependant projects and test fails with "java.lang.NoClassDefFoundError".

This does not happen with NetBeans 7.1.1.
Comment 1 puppala 2012-05-04 09:07:42 UTC
Done some more digging ... the difference between 7.1.1 and 7.1.2 in this case seems to be, that 7.1.1 does NOT use paths to target\classes -folders of dependant projects in the classpath of the test run, but the actual artifacts from Maven repo. That's why the test works with 7.1.1

For some strange reason 7.1.1 also seems to clean those dependant projects (but doesn't build them after clean) !?
Comment 2 Milos Kleint 2012-05-04 13:04:02 UTC
are the tests executed using maven? That can be observed in the output window. Under some conditions, the "compile on save" feature kicks in and then to speed up execution of the tests, we don't execute them using maven, but use a netbeans' own system based on ant and the internal javac compiler.

Please try going to the project's properties dialog and disabling compile on save for tests in the Compile panel.
Comment 3 Milos Kleint 2012-05-04 13:51:44 UTC
(In reply to comment #1)
> Done some more digging ... the difference between 7.1.1 and 7.1.2 in this case
> seems to be, that 7.1.1 does NOT use paths to target\classes -folders of
> dependant projects in the classpath of the test run, but the actual artifacts
> from Maven repo. That's why the test works with 7.1.1
> 

where did you find this information? In Properties of the Test java file?


> For some strange reason 7.1.1 also seems to clean those dependant projects (but
> doesn't build them after clean) !?


I was not able to reproduce the problem, both 7.1.1 and 7.1.2 seem to behave identically to me. Can you provide sample project(s) that demonstrate(s) the problem?
Comment 4 puppala 2012-05-09 07:29:14 UTC
(In reply to comment #2)
> are the tests executed using maven?

Well, the output window unfortunately doesn't show it. But the action is mapped like this (in both versions):

   test-compile surefire:test

and the main class seems to be:

    org.apache.tools.ant.taskdefs.optional.junit.JUnitTestRunner

(In reply to comment #3)
> where did you find this information? In Properties of the Test java file?

I debug tested the file with both IDE versions, and when the process was in a break point, I used jvisualvm to see the system properties of the process - java.class.path among others.

The difference is, how the dependant project is put in the classpath.

NB 7.1.2:

    ...;C:\Temp\target\compa\classes;...

NB 7.1.1:

    ...;C:\Documents and Settings\z705692\.m2\repository\fi\nordea\cafca\compa\5.0-SNAPSHOT\compa-5.0-SNAPSHOT.jar;...

And as I said, the build directories (C:\Temp\target\...) of the dependant project(s) are cleaned in both cases - which causes the problem in a test run with 7.1.2.
Comment 5 Milos Kleint 2012-05-09 08:13:54 UTC
(In reply to comment #4)
> (In reply to comment #2)
> > are the tests executed using maven?
> 
> Well, the output window unfortunately doesn't show it. 

it does. If the output contains "surefire" then it's maven. If it contains an initial gray line with maven cmd line, then it's maven.

>But the action is mapped
> like this (in both versions):
> 
>    test-compile surefire:test
> 
> and the main class seems to be:
> 
>     org.apache.tools.ant.taskdefs.optional.junit.JUnitTestRunner


what is the main class? in context of running tests..

> 
> (In reply to comment #3)
> > where did you find this information? In Properties of the Test java file?
> 
> I debug tested the file with both IDE versions, and when the process was in a
> break point, I used jvisualvm to see the system properties of the process -
> java.class.path among others.
> 
> The difference is, how the dependant project is put in the classpath.
> 
> NB 7.1.2:
> 
>     ...;C:\Temp\target\compa\classes;...
> 
> NB 7.1.1:
> 
>     ...;C:\Documents and
> Settings\z705692\.m2\repository\fi\nordea\cafca\compa\5.0-SNAPSHOT\compa-5.0-SNAPSHOT.jar;...
> 
> And as I said, the build directories (C:\Temp\target\...) of the dependant
> project(s) are cleaned in both cases - which causes the problem in a test run
> with 7.1.2.


well, if the executed test was run by maven in both cases, then it's maven's logic that kicks in, we have no influence whatsoever on the spawned jvm with maven build.

but I suspect one of these executions was performed by ant.
Comment 6 Milos Kleint 2012-05-30 13:01:01 UTC
BTW you have the output directory outside of the project directory? eg. in C:\Temp\target\compa\classes the project's pom.xml  is not placed at C:\Temp, right?

You might some weird problems from that setup in the IDE.
Comment 7 puppala 2012-05-30 18:22:19 UTC
Yes, the build directory is directed to my local disk, because the project is in Clear Case (and you DON'T want to use CC for temporary output target !).

Weird indeed! But 7.2 is coming, so I hope this weird behaviour has disappeared with it.
Comment 8 Milos Kleint 2012-06-01 07:07:00 UTC
I still cannot reproduce the problem locally. Can you create a set of sample
projects that replicate your setup and fail in the same way?

closing temporarily as incomplete, please reopen with the sample projects
attached.