I’m trying to get the most bare-bones gradle project (with tests) to build. Have looked at all related questions and Google searches, and I seem to be missing something very fundamental, and apparently uncommon.
I created one test class, and “gradle compileTestJava” fails to compile the file saying
package org.junit does not exist
It finds the test, knows it’s a test, but can’t seem to find its own junit.jar file.
build.gradle contains
apply plugin: 'java'
and that is it. Bare bones! I also tried adding
dependencies {
testCompile 'junit:junit:4.10'
}
With that I get “Could not resolve all dependencies” which makes me think gradle has lost its way around its own files(?). I see gradle’s installed /Users/me/Documents/Projects/gradle-1.3/lib/plugins/junit-4.10.jar file.
In fact, when I run “gradle dependencies” I get
testCompile - Classpath for compiling the test sources.
No dependencies
I have no idea if that is supposed to include built-in plugin dependencies or not. My guess is that it should list junit.
Other info: * I’m on MacOSx Mountain Lion * I did unzip using the default Finder * I’m assuming that I’ve checked file permissions and paths (gradle -v runs fine) * I’ve set up symlinks to avoid paths with whitespace
Here’s what I get:
:compileTestJava
/Users/me/Documents/Projects/experiment1/src/test/java/MyUnitTests.java:3: package org.junit does not exist
import org.junit.*;
^
/Users/me/Documents/Projects/experiment1/src/test/java/MyUnitTests.java:7: cannot find symbol
symbol
: class Test
location: class test.java.MyUnitTests
@Test
^
/Users/me/Documents/Projects/experiment1/src/test/java/MyUnitTests.java:9: cannot find symbol
symbol
: variable Assert
location: class test.java.MyUnitTests
Assert.assertEquals(2 + 2, 4);
^
3 errors
FAILED
FAILURE: Build failed with an exception.
Lastly, my file structure:
total 16
drwxr-xr-x
5 me
staff
170 Jan 20 20:08 .
drwxr-xr-x
15 me
staff
510 Jan 27 19:29 ..
-rw-r--r--@
1 me
staff
6148 Jan 20 20:08 .DS_Store
drwxr-xr-x
3 me
staff
102 Jan 20 20:08 main
drwxr-xr-x
4 me
staff
136 Jan 20 20:09 test
src/main:
total 0
drwxr-xr-x
3 me
staff
102 Jan 20 20:08 .
drwxr-xr-x
5 me
staff
170 Jan 20 20:08 ..
drwxr-xr-x
2 me
staff
68 Jan 20 20:08 java
src/main/java:
total 0
drwxr-xr-x
2 me
staff
68 Jan 20 20:08 .
drwxr-xr-x
3 me
staff
102 Jan 20 20:08 ..
src/test:
total 16
drwxr-xr-x
4 me
staff
136 Jan 20 20:09 .
drwxr-xr-x
5 me
staff
170 Jan 20 20:08 ..
-rw-r--r--@ 1 me
staff
6148 Jan 20 20:09 .DS_Store
drwxr-xr-x
3 me
staff
102 Jan 27 19:06 java
src/test/java:
total 8
drwxr-xr-x
3 me
staff
102 Jan 27 19:06 .
drwxr-xr-x
4 me
staff
136 Jan 20 20:09 ..
-rw-r--r--
1 me
staff
146 Jan 27 19:06 MyUnitTest.java
Thanks!
Rob