gpt4 book ai didi

java - IntelliJ - 具有多个互连(!)模块的 Gradle 项目

转载 作者:行者123 更新时间:2023-11-30 05:46:08 28 4
gpt4 key购买 nike

我正在使用 IntelliJ IDEA。我习惯于以如下方式使用 Maven 多模块项目:

  1. 创建一个项目。
  2. 创建模块,例如 M1、M2、M0 和 M00。
  3. 设置所有 POM 等 → 完成。

假设模块 M00 是我的项目的公共(public) API,它也由模块 M0 在内部使用,它本身是我的项目的公共(public)私有(private)部分,其他模块模块依赖。

也就是说,M1M2都依赖于M0,而M0也依赖于 M00,即在模块 M1M2 中,我可以使用模块 M0M00< 中的所有代码.

使用 Maven,这一切都非常简单,只需创建模块、编写代码,然后简单地编译它们(配置正确的 POM)。然而,使用 Gradle,我无法从一个模块内部访问另一个模块的代码(类/方法/...)。

我发现的唯一解决方案是与所有内容分开构建上述 M00 模块并将其安装在我的本地 Maven 存储库中,然后对模块 M0 执行相同的操作,然后然后像其他/主模块中的任何其他外部依赖项一样使用这两个模块(M1M2)。

这意味着每次对模块 M0M00 进行任何更改时,我都必须浪费很多时间来做单调而无聊的工作>(使用 Maven 时,IntelliJ 会检测同一项目模块中的代码并自动使用它,而不需要我每次进行更改时都构建和安装“依赖项”)。

有什么方法可以让这个更简单(“类似 Maven”)吗?因为我真的不认为有任何理由在这样的项目中使用 Gradle 否则,因为它只会强化并减慢开发速度。

附注:我对 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'
}

如果链接到问题本身中的我的“示例名称”,模块 torifly-clienttorifly-server 可能会引用示例 M1M2 分别,模块 torifly-sdk 可能是 M00torifly-protocol 可能是模块 M0 。模块 torifly-updater 是一个单独的独立模块,未连接到该项目内的任何其他模块。

最佳答案

如果我正确理解您的问题,您只想在模块之间设置依赖关系。这与 Maven 中的工作原理基本相同。

模块 M0 - build.gradle

dependencies {
compile project(':M00')
}

对于每个模块间依赖关系都必须执行此操作。欲了解更多信息,请参阅Gradle docs .

关于java - IntelliJ - 具有多个互连(!)模块的 Gradle 项目,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54808997/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com