Question

I created a simple example(the names don't really mean anything):

folder structure:

gradleMultiProject
    build.gradle
    core
        build.gradle
        src
            main
                java
                    Core.java
    database
        build.gradle
        src
            main
                java
                    Database.java
    settings.gradle
    webapp
        build.gradle
        src
            main
                java
                    Webapp.java

Below are the files mentioned above:

build.gradle (root gradle build file under gradleMultiProject folder)

subprojects {
    apply plugin: 'java'
    apply plugin: 'eclipse'
}

settings.gradle include 'core', 'database', 'webapp'

gradleMultiProject\core\src\main\java\Core.java

package main.java;

public class Core
{
    public static String HELLO_MESSAGE = "hello world!";
}

Core's build.gradle

task hello {
    println "hello from core!"
}



gradleMultiProject\database\src\main\java\Database.java

package main.java;

public class Database
{
  public void saveMessage()
  {
    System.out.println(Core.HELLO_MESSAGE);
  }
}

Database's build.gradle

dependencies {
    compile project(':core')
}



gradleMultiProject\webapp\src\main\java

package main.java;

public class Webapp
{
  public static void main(String[] args)
  {
    Database database = new Database();
    database.saveMessage();
    System.out.println(Core.HELLO_MESSAGE);
  }
}

Webapp's build.gradle

dependencies {
    compile project(':database')
}





Gradle compiles everything just fine(gradle build). It even lists the transitive dependencies just fine(gradle dependencies). But when I try to generate a .classpath file(gradle eclipseClasspath) for the webapp project it doesn't include core.

WHY?!?!?!?!?!

Was it helpful?

Solution

Actually this isn't a problem because eclipse "exports" core in database. What that means is that it will show up in any project that require the database project.

I just created this exact project and ran "gradle eclipse" and there are no build errors because the webapp project requires the database project and the database project requires and exports the core project. To see more look at the build path in eclipse.

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