Question

I am actually using the newly released Gradle 2, but having the same issues as described in the previous post.

I am also a newb trying to follow the example given in the Spring guide (http://spring.io/guides/gs/gradle/#scratch) but after my first compile, there were no classes.

I have tried various configurations of tree structure including adding the structure and code suggested in the above thread:

"I guess the source file path is src/org/gradle/example/simple/HelloWorld.java. (The diagram shows something different.) That doesn't match Gradle's default, so you'll have to reconfigure it: sourceSets.main.java.srcDirs = ["src"] – Peter Niederwieser Dec 7 '12 at 1:23 "

adding the line: sourceSets.main.java.srcDirs = ["src"] allows the code to compile, however, I still have no classes.

Here is the successful build.

:compileJava UP-TO-DATE
:processResources UP-TO-DATE
:classes UP-TO-DATE
:jar UP-TO-DATE
:assemble UP-TO-DATE
:compileTestJava UP-TO-DATE
:processTestResources UP-TO-DATE
:testClasses UP-TO-DATE
:test UP-TO-DATE
:check UP-TO-DATE
:build UP-TO-DATE

BUILD SUCCESSFUL

Total time: 4.468 secs

Here is the build file:

apply plugin: 'java'
sourceSets.main.java.srcDirs=["src"]

repositories {
    mavenLocal()
    mavenCentral()
}

dependencies {
    compile "joda-time:joda-time:2.2"
 }

jar {
    baseName = 'gs-gradle'
    version = '0.1.0'
}

task wrapper(type:Wrapper) {
    gradleVersion = '1.11'
}

apply plugin: 'application'

mainClassName = 'hello.HelloWorld'

Where are my classes? Please help.

Was it helpful?

Solution

After I got stuck with the same problem, I hacked around for a bit before I understood the reason for this behavior. My project structure was like so

MyProject
  - src
    - main
      - java
        - hello
          HelloWorld.java
          build.gradle

The problem was that the build.gradle is supposed to be under the Project-Root folder i.e. MyProject and not under the hello folder !!!

Changed it so that my Project structure looks like below, ran the gradle build and saw that classes folder was created:

MyProject
  - src
    - main
      - java
        - hello
          HelloWorld.java
build.gradle

When you think about it, the build.gradle is used to build the complete project and not just the classes within one folder and should rightfully sit under the project-root folder.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top