IntelliJ - Gradle 具有多个互连(!)模块的项目
IntelliJ - Gradle project with several interconnected(!) modules
我正在使用 IntelliJ IDEA。我习惯于以如下方式在其中使用 Maven 多模块项目:
- 创建项目。
- 创建模块,例如 M1、M2、M0 和 M00。
- 设置所有 POM 等 → 完成。
假设模块 M00
是我项目的一个 public API,它也被模块 M0
在内部使用,它本身是其他模块依赖的我的项目。
即M1
和M2
都依赖于M0
,而M0
也依赖于M00
,即在模块M1
和 M2
我可以使用模块 M0
和 M00
.
中的所有代码
使用 Maven,这一切都非常简单,只需创建模块、编写代码,然后简单地编译它们(配置适当的 POM)。但是,使用 Gradle,我无法从一个模块内部访问另一个模块的代码 (classes/methods/...)。
我找到的唯一解决方案是将上述 M00
模块与所有内容分开构建,并将其安装在我的本地 Maven 存储库中,然后对模块 M0
执行相同的操作,然后使用这两个模块就像 other/main 模块(M1
和 M2
)中的任何其他外部依赖项一样。
这意味着每次我对模块 M0
或 M00
进行任何更改时,我都必须 浪费 很多时间来做那些单调乏味的工作(使用 Maven 时,IntelliJ 会从同一项目的模块中检测代码并自动使用它,而不是让我在每次进行更改时总是构建和安装 "dependencies")。
有什么方法可以使这个更简单吗("Maven-like")?因为我真的没有看到任何理由为这样的项目使用 Gradle 否则 因为它只会加固并减慢开发速度。
P.S.: 我非常 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'
}
如果在问题本身链接到我的 "example names",模块 torifly-client
和 torifly-server
可能分别引用示例 M1
和 M2
,模块 torifly-sdk
可能是 M00
而 torifly-protocol
可能是模块 M0
。模块 torifly-updater
是一个单独的独立模块,未连接到此项目内的任何其他模块。
如果我正确理解你的问题,你只是想设置模块之间的依赖关系。这与 Maven 中的工作方式基本相同。
模块 M0 - build.gradle
dependencies {
compile project(':M00')
}
必须为每个模块间依赖项完成此操作。有关详细信息,请参阅 Gradle docs。
我正在使用 IntelliJ IDEA。我习惯于以如下方式在其中使用 Maven 多模块项目:
- 创建项目。
- 创建模块,例如 M1、M2、M0 和 M00。
- 设置所有 POM 等 → 完成。
假设模块 M00
是我项目的一个 public API,它也被模块 M0
在内部使用,它本身是其他模块依赖的我的项目。
即M1
和M2
都依赖于M0
,而M0
也依赖于M00
,即在模块M1
和 M2
我可以使用模块 M0
和 M00
.
使用 Maven,这一切都非常简单,只需创建模块、编写代码,然后简单地编译它们(配置适当的 POM)。但是,使用 Gradle,我无法从一个模块内部访问另一个模块的代码 (classes/methods/...)。
我找到的唯一解决方案是将上述 M00
模块与所有内容分开构建,并将其安装在我的本地 Maven 存储库中,然后对模块 M0
执行相同的操作,然后使用这两个模块就像 other/main 模块(M1
和 M2
)中的任何其他外部依赖项一样。
这意味着每次我对模块 M0
或 M00
进行任何更改时,我都必须 浪费 很多时间来做那些单调乏味的工作(使用 Maven 时,IntelliJ 会从同一项目的模块中检测代码并自动使用它,而不是让我在每次进行更改时总是构建和安装 "dependencies")。
有什么方法可以使这个更简单吗("Maven-like")?因为我真的没有看到任何理由为这样的项目使用 Gradle 否则 因为它只会加固并减慢开发速度。
P.S.: 我非常 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'
}
如果在问题本身链接到我的 "example names",模块 torifly-client
和 torifly-server
可能分别引用示例 M1
和 M2
,模块 torifly-sdk
可能是 M00
而 torifly-protocol
可能是模块 M0
。模块 torifly-updater
是一个单独的独立模块,未连接到此项目内的任何其他模块。
如果我正确理解你的问题,你只是想设置模块之间的依赖关系。这与 Maven 中的工作方式基本相同。
模块 M0 - build.gradle
dependencies {
compile project(':M00')
}
必须为每个模块间依赖项完成此操作。有关详细信息,请参阅 Gradle docs。