Can I run IntelliJ unit tests in a maven project without re-running maven goals? - maven

I have a project with a deep maven structure and am evaluating switching from Eclipse to IntelliJ.
I've imported the top-level pom.xml. I know that I can:
Build the whole project with maven goals (I use 'test-compile' to build the test classes)
Run the tests from the IntelliJ test runner. This seems to find the classes/test-classes from the target folder of the project.
However, I would like to just change a test or the code under test, save it, and rerun it without having to manually run the maven test-compile again (like I could with Eclipse). Is this possible with IntelliJ?
I think the issue is that the IntelliJ 'Build Project' action does not build the test classes (and other classes) into the target folder that the test runner looks in.

If you import a Maven project in IntelliJ IDEA, you will be able to build and run the tests from the IDE instead of Maven which is a lot faster because of the incremental compilation.
Make sure this option is disabled and use JUnit Run/Debug configuration, don't run the maven goals.

Thanks to the suggestion from #CrazyCoder, I was able to get this working by following these steps, as I think the issue was Eclipse artifacts fighting with IntelliJ artifacts:
Remove all .classpath, .project and .iml files from the entire code tree
Remove .idea from the root - we need to start again
Open the top-level pom.xml in IntelliJ
If needed, perform a mvn compile (needed for me due to some generated sources)
Rebuild your project
After this, don't open your project in Eclipse again!

Related

Maven Build Scripts Found - IntelliJ - What are the build scripts, where are they cached?

So basically, as the title of the post states, I'm wondering what IntelliJ is referring to when it says that Maven build scripts were found? Are these scripts that Maven keeps cached or are they IntelliJ specific? If they are generated by Maven, where are they stored/ how can I view them if that is possible?
Thanks!
This notification is to inform you that you are working with IntelliJ IDEA project that is not linked to the external build system (Maven or Gradle).
When you open a project in IntelliJ IDEA that was not initially imported from Maven/Gradle and IDE detects pom.xml or build.gradle files in the project, it will display a notification so that you can properly import the project from the build script.
Build script in your specific case is a pom.xml file stored inside a project directory. It's recommended that you open Maven projects by importing the root pom.xml file.
When a project is not imported from the external build system, your source roots configuration may be incomplete and you may be missing the dependencies.

Having Maven Plugins in IntelliJ IDEA without Maven Installation in Computer

I just started to use Maven and IntelliJ IDEA.
I imported a project into IntelliJ IDEA which requires Maven. I didn't install Maven to my computer but I have 2 plugins in IntelliJ IDEA named as "Maven" and "Maven Extension". And the code I have is running without any dependency problem.
In that case, do I still need to install Maven from the web or just the plugins in the IntellJ are enough for projects with Maven?
Can we say that for every project? If someone can explain the logic behind I would be very happy.
Thanks a lot!
Intellij comes with a bundled version of Maven (see File -> Settings -> Build, Execution, Deployment -> Build Tools -> Maven; the property 'Maven home directory' on that screen by defaults points to 'Bundled (Maven 3)').
You don't have to, but you can still install your own version of Maven, and point that property to it. It has the advantage of being able to run maven from the command-line, which is a better guarantee of build-stability (i.e. building the same project in different environments with the same result) than building directly inside of your IDE. And often is way more helpful in investigating build problems.

Eclipse build path is incorrect using maven

I am working on to run the WebObjects project using maven. I build and run the project successfully but the problem is that the execution directory path is from build folder, not target folder. For example: - X:\WOMavenProject\ProjectName\build\ProjectName.woa\..... But it should be target in place of build.
Is maven building the project, or are you getting it invoked with maven? The phrase "I am working on to run the ... project" is not clear.
If the WOLips Incremental Builder is being used to build the project, it will pu the build products into the build directory.
When I use the Ant Builder, it builds into dist.
Presumably you have installed the Maven Builder. I assume here is one, but I have never used it. How is it configured? Does the Builder allow you to specify where the build products will appear?

How to configure Hudson to use Maven for dependecies and run JUnit

In Eclipse I have my "Dynamic Web Project" configured with Maven taking care automatically of all my dependencies (once I specify them in pom.xml). After implementing my Unit Tests I can simply run them all by right-clicking on project and selecting: Run As -> JUnit Test.
How/where can I now configure Hudson so after checkout of all my sources from SVN repository it would automatically invoke(?) Maven (to download all dependencies) and then run all available tests with JUnit?
When you set up a project in Hudson (now Jenkins) in the configuration page you may choose the build phases that Jenkins will run. Then it will run them in the order you specify. There you will have Maven steps where you'll define your goals.
Jenkins itself has to know where to find a Maven installation (or Ant, or any other command that it must run to build). This could be done in the server configuration page.
I think that's the default behavior of Hudson (compiling + running tests).
Did you commit on your svn repository the pom.xml file?

mvn test on multi module project?

I have a strange issue and I don't know if my conclusion is correct. I have a multi module project with two children:
Rector build order:
mvn-project-test
mvn-project-core
core depends on test (so the build order is correct). Of course, running 'mvn test' doesn't install any artifacts locally. When running it, maven complaints (correctly) that ~/.m2/respositories/...../mvn-project-test-1.0-SNAPSHOT.jar is missing and the core build fails.
Shouldn't maven use the dependencies from the target folder of other multimodule children? Or must I always use 'mvn test install' on multi module projects? (Or third, I'm completely wrong and my whole project configurationis somehow broken)
Finally, the test project hasn't any content, yet, just dependencies so the jar is empty. But that shouldn't be a problem, right?
Cheers,
Jan
There were ideas for Maven 3 to allow the various mojos to see the whole build and do magic like "if none of my upstream projects changed, skip my tests" and things like that.
But as it is, each module is independent. Dependencies will only be resolved from the local repository. So if you don't mvn install, your tests won't work.

Resources