Reputation: 369
I am using IntelliJ IDEA. I am used to work with Maven multi-module projects in it in a way like follows:
Let's say module M00
is a public API of my project, which is also used internally by module M0
, which itself is a common private part of my project which other modules depend on.
That is, M1
and M2
both depend on M0
, while M0
also depends on M00
, that is, in modules M1
and M2
I can use all the code from modules M0
and M00
.
With Maven, this is all as simple as just creating the modules, writing code, and then simply compiling them (with proper POMs configured). With Gradle, however, I cannot access code (classes/methods/...) of one module from inside another.
The only solution I found is to build the aforementioned M00
module separately from everything and install it in my local Maven repository, then do the same for module M0
, and then use both modules just like any other external dependencies in other/main modules (M1
and M2
).
This means that I have to waste really much time doing that monotonous and boring work every time I make any changes to modules M0
or M00
(while with Maven, IntelliJ detects code from modules of the same project and uses it automatically, without making me always build and install the "dependencies" every time I make a change).
Is there any way to make this simpler ("Maven-like")? Because I don't really see any reasons to use Gradle for such a project otherwise since it only hardens and slows down the development.
P.S.: I am very new to Gradle
My project structure:
torifly
├── build.gradle
├── gradle
│ └── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── gradlew
├── gradlew.bat
├── settings.gradle
├── src
│ ├── main
│ │ ├── java
│ │ └── resources
│ └── test
│ ├── java
│ └── resources
├── torifly-client
│ ├── build.gradle
│ └── src
│ ├── main
│ │ ├── java
│ │ └── resources
│ └── test
│ ├── java
│ └── resources
├── torifly-protocol
│ ├── build.gradle
│ └── src
│ ├── main
│ │ ├── java
│ │ └── resources
│ └── test
│ ├── java
│ └── resources
├── torifly-sdk
│ ├── build.gradle
│ └── src
│ ├── main
│ │ ├── java
│ │ └── resources
│ └── test
│ ├── java
│ └── resources
├── torifly-server
│ ├── build.gradle
│ └── src
│ ├── main
│ │ ├── java
│ │ └── resources
│ └── test
│ ├── java
│ └── resources
└── torifly-updater
├── build.gradle
└── src
├── main
│ ├── java
│ └── resources
└── test
├── java
└── resources
Contents of the root 'settings.gradle' file
rootProject.name = 'torifly'
include "torifly-client"
include "torifly-protocol"
include "torifly-server"
include "torifly-sdk"
include 'torifly-updater'
Contents of the root
build.gradle
file
buildscript {
repositories {
mavenCentral()
mavenLocal()
jcenter()
}
}
subprojects {
repositories {
mavenCentral()
mavenLocal()
jcenter()
}
apply plugin: 'java'
apply plugin: 'idea'
sourceCompatibility = 1.8
targetCompatibility = 1.8
dependencies {
testCompile group: 'junit', name: 'junit', version: '4.12'
}
}
Contents of other (modules') 'build.gradle' files
These files are all the same and only differ in name (
group
)
plugins {
id 'java'
id 'idea'
}
group 'net.torifly.protocol'
version '1.0.0'
dependencies {
compile group: 'me.darksidecode.easysockets', name: 'EasySockets', version: '1.0.0'
}
If linked to my "example names" in the question itself, modules torifly-client
and torifly-server
may refer to samples M1
and M2
respectively, module torifly-sdk
may be M00
and torifly-protocol
could be module M0
. Module torifly-updater
is a separate standalone module not connected to any other modules inside this project.
Upvotes: 1
Views: 701
Reputation: 4841
If I understand your problem correctly you just want to setup dependency between your modules. This works basically the same as is would in Maven.
Module M0 - build.gradle
dependencies {
compile project(':M00')
}
This has to be done for every inter-module dependency. For more information see Gradle docs.
Upvotes: 1