2

I'm trying to build multi project with flat style.

Expected result is that gradle build under baseproj directory compile and build using libsproj directory's libraries.

This is my directory structure.

workspace
├── baseproj
│   ├── build.gradle
│   └── settings.gradle
│   └── src/main/java/sample.java
└── libsproj
    ├── batch
    │   ├── foo.jar
    │   └── some.jar
    └── web
        ├── hoge.jar
        └── some.jar

Here is my build.gradle:

apply plugin: "java"
apply plugin: "application"

jar.baseName = 'base'
version = ''
def mainClass = 'sample'
mainClassName =  mainClass

repositories {
  mavenCentral()
}

project(':libsproj') {
  dependencies {
    compile fileTree(dir: "${projectDir}/libs", include: '*.jar')
  }
}

dependencies {
  compile project ':libsproj'
  testCompile 'junit:junit:4.12'
}

and here is setting.gradle:

rootProject.name = 'baseproj'
rootProject.projectDir = new File(settingsDir, 'baseproj')
includeFlat 'libsproj'

and also this is gradle projects output:

------------------------------------------------------------
Root project
------------------------------------------------------------

Root project 'baseproj'
\--- Project ':libsproj'

If I run gradle build, it says just successful, but it did not build my Java file.

:buildEnvironment

------------------------------------------------------------
Root project
------------------------------------------------------------

classpath
No dependencies

BUILD SUCCESSFUL

I understand if I create settings.gradle under the root dir (i.e. workspace dir in this example.), but this directory structure will be like the following:

├── anotherproj
├── baseproj
├── libsproj
│   ├── batch
│   └── web
└── otherproj

otherproj needs libsproj, and anotherproj needs libsproj and baseproj, and so on.

At this time, I can workaround with fileTree in build.gradle like the following:

compile fileTree(dir: "../libsproj/batch", include: '*.jar')

But, it will be stuck when some other project is added. (e.g. otherproj on the above)

So, how can I build with multi flat directory. Do you have any ideas? Please give me a hand.

FYI: Before post this question, I checked these questions.

Community
  • 1
  • 1
tkhm
  • 860
  • 2
  • 10
  • 30

2 Answers2

1

From my practice it's very useful to have a separate repository for each Gradle build.

But for your specific case you can just fix include wildcard expression:

compile fileTree(dir: "${projectDir}/libs", include: '**/*.jar')
Vyacheslav Shvets
  • 1,735
  • 14
  • 23
  • Thank you for your comment. First of all, I agree with your comment about repository separation. I often do so in my personal project. – tkhm Jan 31 '17 at 11:55
  • Your `include: '**/*.jar'` is very great if I could do that on the workspace directory on the above example. Maybe my question is ambiguous, but I must do that on `otherproj` or `anotherproj` or so. Anyway, if I did it with like the following: `include: '../**/*.jar', exclude: otherproj`, it will be the one of alternative solutions. – tkhm Jan 31 '17 at 12:02
1

Try the following

Add this into your workspace/buildproj/settings.gradle file

 includeBuild '../libsproj/web'

Had a similar issue - as it looks that works for me - it brings some MultiRepo convenience into the gradle world.

Hubert Ströbitzer
  • 1,745
  • 2
  • 15
  • 19