JUnit4 plug-in and build path for junit.jar in Eclipse - eclipse

I've got Eclipse (Helios) installed along with the JUnit3, JUnit4 and Java Development Tools plug-ins for some Android development.
I've created some unit tests but the only way they run (without throwing a java.lang.ClassNotFoundException for org.junit.Test) is if I add an External JAR to the test project build path for junit.jar from the normal JUnit install I have.
Why isn't Eclipse able to reference the junit.jar from the JUnit4 plugin which I can see when I expand the library in Package Explorer? In fact I can remove the JUnit4 Library from the test project leaving just the External JAR and the tests run fine.
I tried adding the path to the plug-in folder to my CLASSPATH system environment variable as I had to setting up JUnit but this made no difference. The plugin path is created as a JUNIT_HOME Classpath Variable in Eclipse but this is labeled as deprecated.
Do I even need the JUnit3 and JUnit4 plugins as these must have come with the distro I used?

In any new project, the sure way I add the required Junit deps (with the exception of declaring them in maven) is through creating the test using the in-built Junit test shortcut.
Go to New > Junit Test Case. If the right deps are not on the project classpath, eclipse will pull them in automatically.

Related

Eclipse cannot run Spock tests with source folder disappearing

I've encountered a very curious case about Eclipse and Spock tests.
I have Eclipse 4.5.2 (Build id: 20160218-0600) with Groovy compilers plugins installed, Groovy-Eclipse M2E Integration and Groovy-Eclipse Feature, all in version: 2.9.2.xx-201604081629-e45.
In this Eclipse I have a maven project configured to compile and run Spock tests. In Eclipse I have src/test/groovy folder configured as a source folder and it is holding my spock tests. Both maven and Eclipse can run the tests just fine.
Recently my friend has had a problem with the same setup, so I tried to reproduce it. And now I have the same Eclipse 4.5.2 (Build id: 20160218-0600) with Groovy plugin (and this is the weird part, I used the same update site for these plugins but the build version is different, it is: 2.9.2.xx-201607251752-e45). I imported the same maven project, however, when I try to run Spock tests the curious thing happens: the src/test/groovy source folder dissappears from the project and on the console I can see ClassNotFoundException with the name of the Spock test class. Here is a short summary how it looks like:
We tried the same also in Eclipse Neon and Spring STS and we have the same result. (In IntelliJ the same project runs just fine).
I'm starting ti thing that this may be related to the Groovy plugins, which might have got changed in the latest build and a bug was introduced. However, I hope I am mistaken.
Any thoughts?

How to script maven commands in Eclipse

I have a maven project in Eclipse with a bunch of local project dependencies.
Building with the Maven assembly plugin or shade plugin is a pain because I first have to build and install all of the local project dependencies before I can build my main project.
Does m2e provide a way to script a sequence of arbitrary maven commands? I know I can script everything from the command line, I just don't know where m2e's instance of maven is installed, and I'd like to avoid installing a separate instance.
Have you considered creating a multi-module Maven project that "contains" the dependencies? That would allow you to build just the container and Maven automatically takes care of building the component modules. Eclipse's m2e supports multi-module builds so there wouldn't be anything special to do for Eclipse.

Running Gradle inside Eclipse?

There appears to be an Eclipse plugin for Gradle, but no Gradle plugin for Eclipse...
Simply, I'd like to add a build.gradle to my Eclipse project, write its contents (including defining its dependencies), and then run it from inside Eclipse, the same way I can run Ant scripts from inside Eclipse.
When it runs, I'd expect the plugin to pull down all dependencies and make them available to my project's classpath in Eclipse.
If no such plugin exists, then I ask: what's the best way to develop in Eclipse, but keep your builds managed by Gradle? If I decide I need a new xyz.jar as a dependency for my code, how do I add it as a dependency in such a way that both Gradle and Eclipse will recognize it (and not throw compiler errors)?
Either use the IDE project generation approach (gradle eclipse), or use the Eclipse Gradle Integration. In both cases, you'll want to apply plugin: "eclipse".
The Gradle plugin for Eclipse is part of the Spring IDE. It understands the dependencies specified in the build script and makes those available in the .classpath.

Is there a one step build for a GWT application or module in Intellij 11/12?

Intellij doesn't seem to have a one step way to build a war file from a GWT application. Or am I missing the option somewhere?
I would suggest to use maven for project description.
IntelliJ works very good with maven projects. You can use IntelliJ for development and maven for production-builds.
update
You can find the documentation here:
http://mojo.codehaus.org/gwt-maven-plugin/
Steps, to get the stuff running:
Install maven
Create a pom.xml
define you dependencies
call mvn install and verify you war-file (it will be created in the sub-directory "target"
call mvn idea:idea this will create a Intellj project
OR
Open Intellij, select "new project from external model -> from maven"

How eclipse maven and ant work together?

I made simple maven project and I opened it with Eclipse. I have installed maven plugin for Eclipse. I'm interested in following:
How Eclipse compiles code when I hit save on my source code (does it use configuration from ant or maven or something else)?
When I run tests from JUnit plugin for Eclipse those Eclipse calls mvn test (I suppose not, but what is then happening exactly)?
Is it possible that maven does the build successfully but Eclipse is
showing errors in code?
The Maven Integration for Eclipse makes it easier to edit POM files, allows you to execute maven builds from within Eclipse and to help with dependency management. It doesn't actually compile your code (unless of course you execute a maven build from within Eclipse). The main help is with the dependency management and writing the .classpath file of your project within Eclipse.
To try and answer your questions:
Eclipse uses its standard mechanism to compile code. With a standard eclipse for java developers your project will have a Java Project nature and Eclipse will then use the Java Development Tools - JDT to compile the code. (Internally this uses an incremental builder to build the code http://help.eclipse.org/juno/index.jsp?topic=%2Forg.eclipse.platform.doc.isv%2Fguide%2FresAdv_builders.htm). What source files it will compile and where it will place the resultant .class files is configured in your project's Java Build Path (which I am guessing the maven plugin may well configure for you)
JUnit support is part of the Java Development Tools as well.
It is possible that maven will successfully build a project outside of Eclipse, but that the same project will show errors within Eclipse. This is usually down to classpath errors (dependencies defined in the project's POM not being added to the classpath in Eclipse). If you are using the maven plugin with eclipse this probably shouldn't happen. If you are not using the maven plugin within eclipse you can execute maven eclipse:eclipse to have maven update the Eclipse .classpath file of the project which should then fix any of these problems.