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

时间:2018-06-09 08:09:49

标签: 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 module时,我得到了:

  

11:14:38 AM:执行任务'build'......

     

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

     

错误:包org.rustygnome.pow.lib.config不存在

     

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

     

// ...进一步的问题......

1 个答案:

答案 0 :(得分:1)

Composite builds似乎就是你所需要的。

Gradle reference for the composite builds feature

您也可以使用Multi-Projects

相关问题