Gradle 2.4 and Eclipse Mars here. Here's my project directory structure:
myapp/ <-- root project
myapp-client/
src/main/groovy/*
build.gradle <-- just declares some client-specific deps
myapp-shared/
src/main/groovy/*
build.gradle <-- shared-specific deps
myapp-server/
src/main/groovy/*
build.gradle <-- server-specific deps and how to package server JAR
build.gradle
settings.gradle
Where myapp/build.gradle
is:
allprojects {
apply plugin: 'groovy'
apply plugin: 'eclipse'
apply plugin: 'maven'
apply plugin: 'codenarc'
sourceCompatibility = '1.8'
targetCompatibility = '1.8'
[compileJava, compileTestJava]*.options*.encoding = 'UTF-8'
repositories {
// ...etc.
}
dependencies {
// ...etc.
}
task wrapper(type: Wrapper) {
gradleVersion = '2.4'
}
}
And where myapp/settings.gradle
is:
include ':myapp-shared'
include ':myapp-client'
include ':myapp-server'
When I do a ./gradlew eclipse
I get messages indicating that the command was successful. I then open Eclipse to import myapp
as a series of individual subprojects.
In previous projects that contained subprojects, I would go to Import >> Existing Projects into Workspace
, where I would see this dialog:
I would then click Browse
and select the project root (in this particular case, myapp
). Eclipse would then auto-detect the 3 subprojects and populate them as a checked list inside the Projects component in the UI above. I would then click "Finish" and Eclipse would load the 3 subprojects into my workspace, each showing as a separate project (as it should).
Instead, when I click on myapp
as the root project, Eclipse just populates it as a single project, almost as if it doesn't detect that I have subprojects at all:
When I click Finish it imports a single project into my workspace, that has source folders for each of the 3 subprojects. And while that's just an annoyance, the real problem is that the classpath seems to be totally jacked up. For instance, I can add a class to myapp-shared
, and then include it in a class defined inside myapp-client
, and Eclipse doesn't force me to add an import
statement into the client class! It's like the whole project is sharing the same package/namespace.
Can any Gradle gurus spot a defect in my Gradle setup that could be the cause of this?
Run Eclipse. Select the "File" > "Import" option from the menu: Select the "Gradle" > "Existing Gradle Project" option.
In a multi-project gradle build, you have a rootProject and the subprojects. The combination of both is allprojects. The rootProject is where the build is starting from. A common pattern is a rootProject has no code and the subprojects are java projects.
This was nasty, but I figured it out. Posting the solution here in case anybody else runs into this.
allprojects
closure, you need allprojects
and subprojects
closures. Not sure what is "safe" to put in either closure, but I got this working by simply declaring my repositories
inside of allprojects
and then putting everything else inside subprojects
.gradle eclipse
on the root project (before I added in the subprojects
closure), and so Gradle generated the typical artifacts (e.g. .projects
, .classpath
, .settings/*
) in the parent/root project directory. So...gradle clean
for good measure. Probably not needed.gradle eclipse
again.If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With