java - IntelliJ IDEA 中三个 java 模块的项目设置,其中一个用作另外两个模块的模块

标签 java gradle intellij-idea project

我正在尝试在 IntelliJ IDEA 中设置基于 Gradle 的多模块 java 项目:

三个模块(我猜),其中一个是由其他两个模块使用的库。我未能正确配置项目,也许有人可以在这里给我提示:

根据我从其他模块引用库模块的方式,我设法让语法突出显示找到引用(导入)的类,但这对编译器不起作用,仍然提示找不到类。 所以我想我的问题是:从项目结构设置中的其他两个模块引用库模块中的类的正确方法是什么?

这是设置:

/..../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 {
}

library/build.gradle:

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'
}

spring/build.gradle:

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 模块。在该模块源中,我引用了 library 模块中的一个类:

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

library 模块已构建,没有任何问题。

但是当我尝试构建 spring 模块 时,我得到:

11:14:38 AM: Executing task 'build'...

/data/Projects/pow/spring/src/main/java/org/rustygnome/pow/spring/Application.java:3:

error: package org.rustygnome.pow.lib.config does not exist

import org.rustygnome.pow.lib.config.Config;

// ... further issues...

最佳答案

Composite builds似乎正是您所需要的。

Gradle reference for the composite builds feature .

您还可以使用Multi-Projects .

关于java - IntelliJ IDEA 中三个 java 模块的项目设置,其中一个用作另外两个模块的模块,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50772226/

相关文章:

java - map 并发修改问题

Java,从文件分配变量

android - ActionBar Sherlock 与 Android Studio 0.2.2

android - 如何在不同的Android构建版本之间共享依赖项?

java - Gradle 构建失败 : java. util.zip.ZipException : duplicate entry: org/apache/commons/io/CopyUtils. 类

java - 如何向下转换 Java 对象?

java - 编辑 xml 元素的 "app"属性

java - 错误 :maven-resources-test:twitter_storm_new: java. lang.NegativeArraySizeException

grails - 在 IntelliJ IDEA 9.0.x 中创建 Grails 应用程序无法提示输入 "create-app"

scala - 在包对象中使用案例类时类型不匹配