Reputation: 42915
I am trying to setup a multi module java project based on Gradle in IntelliJ IDEA:
Three modules (I guess), one meant as a library that is used by the two other modules. I fail to get the project configuration right, maybe someone can give me a hint here:
Depending on how I reference the library module from the other modules I manage to get the syntax highlighting find the referenced (imported) classes, but that does not work for the compiler, that one still complains about classes not found. So I guess my question is: what is the right approach to reference the classes in the library module from the other two modules in the project structure setup?
This is the setup:
/..../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')
}
Using that setup I want to assemble the spring
module. In that modules sources I reference a class from the library
module:
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
The library
module is built, no issues there.
But when I try to build the spring module
I get:
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...
Upvotes: 0
Views: 230
Reputation: 401965
Composite builds seems to be what you need.
Gradle reference for the composite builds feature.
You can also use Multi-Projects.
Upvotes: 1