IntelliJ IDEA中的三个java模块的项目设置,其中一个用作其他两个模块
我正在尝试基于IntelliJ IDEA中的Gradle设置一个多模块java项目: 我猜有三个模块,其中一个是其他两个模块使用的库。我无法正确配置项目,也许有人可以在这里给我一个提示: 根据我从其他模块中引用库模块的方式,我设法获得语法高亮显示,以找到被引用(导入)的类,但这对编译器不起作用,编译器仍然抱怨找不到类。 所以我想我的问题是:从项目结构设置中的其他两个模块引用库模块中的类的正确方法是什么 以下是设置:IntelliJ IDEA中的三个java模块的项目设置,其中一个用作其他两个模块,java,gradle,intellij-idea,project,Java,Gradle,Intellij Idea,Project,我正在尝试基于IntelliJ IDEA中的Gradle设置一个多模块java项目: 我猜有三个模块,其中一个是其他两个模块使用的库。我无法正确配置项目,也许有人可以在这里给我一个提示: 根据我从其他模块中引用库模块的方式,我设法获得语法高亮显示,以找到被引用(导入)的类,但这对编译器不起作用,编译器仍然抱怨找不到类。 所以我想我的问题是:从项目结构设置中的其他两个模块引用库模块中的类的正确方法是什么 以下是设置: /..../pow/library /spring
/..../pow/library
/spring
/droid
setup.gradle
:
rootProject.name = 'pow'
include 'library'
include 'spring'
include 'droid'
build.gradle
:
group 'org.rustygnome.pow'
version '1.0-SNAPSHOT'
allprojects {
group 'org.rustygnome.pow'
version '1.0-SNAPSHOT'
}
repositories {
mavenCentral()
}
dependencies {
}
apply plugin: 'java'
//sourceCompatibility = 1.8
repositories {
mavenCentral()
}
dependencies {
compile 'org.json:json:20171018'
compile 'com.googlecode.json-simple:json-simple:1.1.1'
compile files('/home/arkascha/Projects/Android/Sdk/platforms/android-26/android.jar')
testCompile group: 'junit', name: 'junit', version: '4.12'
}
buildscript {
ext {
springBootVersion = '2.0.1.BUILD-SNAPSHOT'
}
repositories {
mavenCentral()
maven { url "https://repo.spring.io/snapshot" }
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
}
}
apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'idea'
apply plugin: 'org.springframework.boot'
apply plugin: 'io.spring.dependency-management'
bootJar {
mainClassName = 'org.rustygnome.pow.spring.Application'
baseName = 'pow-spring-boot'
version = '0.1.0'
}
sourceCompatibility = 1.8
targetCompatibility = 1.8
repositories {
mavenCentral()
maven { url "https://repo.spring.io/snapshot" }
}
dependencies {
compile('org.springframework.boot:spring-boot-starter')
runtime('org.springframework.boot:spring-boot-devtools')
testCompile('org.springframework.boot:spring-boot-starter-test')
}
库/build.gradle
:
group 'org.rustygnome.pow'
version '1.0-SNAPSHOT'
allprojects {
group 'org.rustygnome.pow'
version '1.0-SNAPSHOT'
}
repositories {
mavenCentral()
}
dependencies {
}
apply plugin: 'java'
//sourceCompatibility = 1.8
repositories {
mavenCentral()
}
dependencies {
compile 'org.json:json:20171018'
compile 'com.googlecode.json-simple:json-simple:1.1.1'
compile files('/home/arkascha/Projects/Android/Sdk/platforms/android-26/android.jar')
testCompile group: 'junit', name: 'junit', version: '4.12'
}
buildscript {
ext {
springBootVersion = '2.0.1.BUILD-SNAPSHOT'
}
repositories {
mavenCentral()
maven { url "https://repo.spring.io/snapshot" }
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
}
}
apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'idea'
apply plugin: 'org.springframework.boot'
apply plugin: 'io.spring.dependency-management'
bootJar {
mainClassName = 'org.rustygnome.pow.spring.Application'
baseName = 'pow-spring-boot'
version = '0.1.0'
}
sourceCompatibility = 1.8
targetCompatibility = 1.8
repositories {
mavenCentral()
maven { url "https://repo.spring.io/snapshot" }
}
dependencies {
compile('org.springframework.boot:spring-boot-starter')
runtime('org.springframework.boot:spring-boot-devtools')
testCompile('org.springframework.boot:spring-boot-starter-test')
}
spring/build.gradle
:
group 'org.rustygnome.pow'
version '1.0-SNAPSHOT'
allprojects {
group 'org.rustygnome.pow'
version '1.0-SNAPSHOT'
}
repositories {
mavenCentral()
}
dependencies {
}
apply plugin: 'java'
//sourceCompatibility = 1.8
repositories {
mavenCentral()
}
dependencies {
compile 'org.json:json:20171018'
compile 'com.googlecode.json-simple:json-simple:1.1.1'
compile files('/home/arkascha/Projects/Android/Sdk/platforms/android-26/android.jar')
testCompile group: 'junit', name: 'junit', version: '4.12'
}
buildscript {
ext {
springBootVersion = '2.0.1.BUILD-SNAPSHOT'
}
repositories {
mavenCentral()
maven { url "https://repo.spring.io/snapshot" }
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
}
}
apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'idea'
apply plugin: 'org.springframework.boot'
apply plugin: 'io.spring.dependency-management'
bootJar {
mainClassName = 'org.rustygnome.pow.spring.Application'
baseName = 'pow-spring-boot'
version = '0.1.0'
}
sourceCompatibility = 1.8
targetCompatibility = 1.8
repositories {
mavenCentral()
maven { url "https://repo.spring.io/snapshot" }
}
dependencies {
compile('org.springframework.boot:spring-boot-starter')
runtime('org.springframework.boot:spring-boot-devtools')
testCompile('org.springframework.boot:spring-boot-starter-test')
}
使用该设置,我想组装弹簧
模块。在该模块中,我引用了库中的一个类
模块:
Application.java
:
package org.rustygnome.pow.spring;
import org.rustygnome.pow.lib.config.Config;
// other imports
@SpringBootApplication
public class Application implements ApplicationRunner {
static ApplicationContext appContext;
static ThreadPoolTaskExecutor taskExecutor;
Config config; // this one references
// further stuff
库
模块已构建,没有问题
但是,当我尝试构建spring模块时,我得到:
上午11:14:38:正在执行任务“生成”
/data/Projects/pow/spring/src/main/java/org/rustygnome/pow/spring/Application.java:3:
错误:包org.rustygnome.pow.lib.config不存在
导入org.rustygnome.pow.lib.config.config
//。。。其他问题
似乎是你需要的
你也可以用。嗯,听起来不错,但我没能成功。无论我是在gradle中手动输入IncludeFild还是使用IDEA项目结构对话框,结果都是一样的。语法突出显示得到满足,我可以从库模块导入类,但编译器仍然抱怨库包不存在。@arkascha IntelliJ IDEA同步只是一种方式,所有更改都应该在gradle生成文件中执行,然后在IDE中刷新。如果命令行Gradle build可以工作,它也应该在IDE中工作。我在settings.Gradle文件中添加了一个“includebild”库,并在IDEA中同步了Gradle dock,没有任何更改。我需要在“项目结构”对话框中添加库文件夹/模块,否则根本找不到它。但正如所说,des对编译器没有帮助。@arkascha请分享。当然,你是对的。我在问题中补充了一些细节,我认为这些是相关的部分。