I have a multimodule project. there is 2 modules:
- server module
- domain module
in the build.gradle of the domain module I put :
group = 'com.xxx.yyyy.zzz'
version = '1.0.0-SNAPSHOT'
and the server module imports the domain module as follow :
dependencies {
compile group: 'com.xxx.yyyy.zzz', name: 'domain', version: '1.0.0-SNAPSHOT'
...
}
howerver he is not able to detect it!
the jar is published to the maven m2 repo and I am able to see it. and i am using mavenLocal to get dependecies from the m2
repositories {
mavenLocal()
mavenCentral()
}
I deleted the gradle cache, stopped the gradle daemon without success!
Any idea ?
the build.gradle of the server module:
group = 'com.xxx.yyy.zzz'
version = '1.0.0-SNAPSHOT'
repositories {
mavenLocal()
mavenCentral()
}
apply plugin: "org.springframework.boot"
apply plugin: "net.ltgt.apt"
apply plugin: "maven"
apply plugin: 'base'
apply plugin: 'maven-publish'
dependencies {
compile group: 'com.xxx.yyy.zzz', name: 'domaine', version: '1.0.0-SNAPSHOT'
// other dependecies ......
}
the build.gradle of the domain module:
group = 'com.desjardins.experiencecredit.gestiondemandes'
version = '1.0.0-SNAPSHOT'
repositories {
mavenLocal()
mavenCentral()
}
apply plugin: "maven"
apply plugin: 'base'
apply plugin: 'maven-publish'
uploadArchives {
repositories {
mavenDeployer {
repository(url: mavenrepo)
}
}
}
jar.finalizedBy uploadArchives
the settings.gradle of the main project :
pluginManagement {
repositories {
gradlePluginPortal()
}
}
rootProject.name = 'XXX'
include 'server'
include 'domaine'
If you have multiple modules in the same project, you should instead declare the dependencies using the project object:
settings.gradle at root project level
rootProject.name = 'my-application'
include 'server'
include 'domain'
Then define the build files - root project build.gradle, server module build.gradle and domain module build.gradle.
In the server module's build.gradle, declare the dependency as follows:
dependencies {
compile project(':domain')
...
}
Refer: https://guides.gradle.org/creating-multi-project-builds/
Related
This issue is widely commented in Stack Overflow, but none of the solutions seems to fit my project.
I have two independant projects (MainApplication and LibraryApplication), then I want to export LibraryApplication , and import it into main project (this is a reduced approach for keeping things simple).
I exported the library.jar to libs/ folder in the main project, then I added the compile files instruction to build.gradle.
The jar is indeed added to the classpath, and I can see the classes from MainApplication. So I added #ComponentScan, #EnableJpaRepositories, #EntityScan, etc. but none of those annotations seems to work, because only MAIN_ENTITY is created when I run the MainApplication project.
LibraryApplication project structure
MainApplication project structure
Only MAIN_ENTITY is created
I tried many of the solutions commented in other related questions, but none works for me:
I moved MainApplication.java to an upper package level without results.
I created an AppConfig.java in LibraryApplication project, and configured #ComponentScan("com.app"),#EntityScan("com.app"), #EnableJpaRepositories("com.app") and injected the class in the MainApplication without results.
I removed the .* from my annotations, so instead of #ComponentScan("com.app.*") I have #ComponentScan("com.app") without results.
How can I achieve the expected results?
I created two github repos so you can check/download the code.
https://github.com/ferdonof/main.git
https://github.com/ferdonof/library.git
Thanks in advance!
UPDATE
Sharing the build.gradle config of each project:
For library
buildscript {
ext {
springBootVersion = '2.0.4.RELEASE'
}
repositories {
mavenCentral()
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
}
}
apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'org.springframework.boot'
apply plugin: 'io.spring.dependency-management'
group = 'com.app'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = 1.8
repositories {
mavenCentral()
}
bootRepackage {
classifier = 'exec'
}
dependencies {
compile('org.springframework.boot:spring-boot-starter-data-jpa')
compile('org.springframework.boot:spring-boot-starter-web')
runtime('com.h2database:h2')
compileOnly('org.projectlombok:lombok')
testCompile('org.springframework.boot:spring-boot-starter-test')
}
For main
buildscript {
ext {
springBootVersion = '2.0.4.RELEASE'
}
repositories {
mavenCentral()
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
}
}
apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'org.springframework.boot'
apply plugin: 'io.spring.dependency-management'
group = 'com.app'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = 1.8
repositories {
mavenCentral()
}
dependencies {
compile files('libs/library.jar')
compile('org.springframework.boot:spring-boot-starter-data-jpa')
compile('org.springframework.boot:spring-boot-starter-web')
runtime('com.h2database:h2')
compileOnly('org.projectlombok:lombok')
testCompile('org.springframework.boot:spring-boot-starter-test')
}
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...
Composite builds seems to be what you need.
Gradle reference for the composite builds feature.
You can also use Multi-Projects.
So I'm just playing (experimenting) with gradle and spring-boot.
When I follow the hello world I easily get the project running which kind of makes me happy.
Now I'd like to have a structured project; For this I'm using Intellij Community (not sure if relevant). I have the following structure.
/Project
- build.gradle
- settings.gradle (only includes Services)
/Project/Services/
- build.gradle
- settings.gradle (only includes MyService)
/Project/Services/MyServices
- build.gradle
Now I can share some of my build.gradle files but I"m trying random things I find on the internet. My problem is that the spring boot classes are not available at MyService. The following directory structure inside the Myservice is standard Java (/src/main/java )
I'm trying to put the dependencies & versions in my main build.gradle if possible. Can someone point out what I'm doing wrong.
Currently I've only used gradle for simple android development work.
/Project/build.gradle
group 'nl.msegers.project'
version '1.0-SNAPSHOT'
apply plugin: 'java'
apply plugin: 'idea'
sourceCompatibility = 1.8
repositories {
mavenCentral()
}
dependencies {
testCompile group: 'junit', name: 'junit', version: '4.11'
}
/Project/Services/build.gradle
group 'nl.msegers.project.services'
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:1.5.2.RELEASE")
}
}
/Project/Services/MyService/build.gradle
group 'nl.msegers.project.services.myservice'
version parent.version
apply plugin: 'java'
apply plugin: 'idea'
apply plugin: 'org.springframework.boot'
jar {
baseName = 'Navigation'
version = parent.version
}
repositories {
mavenCentral()
}
sourceCompatibility = 1.8
targetCompatibility = 1.8
To have every project to inherit the dependencies from the root, you could use the allprojects script block on your root project like:
allprojects {
dependencies {
compile group: 'commons-collections', name: 'commons-collections', version: '3.+'
...
}
}
I've been scouring the web for an hour or so to get a structure like this working. In the meanwhile I've rebuild my project from scratch as well (Though I did not have much code anyway).
My code currently allows simple Spring boot sub projects without too much redundant configuration, and they can pretty easily compile the Libraries project, however this can use some work.
What I've got now is a structure like this.
/Project
/Project/Libraries
/Project/Libraries/Models
/Project/Services/
/Project/Services/Service
With the only notable build.gradle files (others are nearly empty):
/Project/Services/
group 'nl.msegers.project.services'
version parent.version
buildscript {
ext {
springBootVersion = "1.5.2.RELEASE"
}
repositories {
mavenCentral()
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
}
}
subprojects {
buildscript {
ext {
springBootVersion = "1.5.2.RELEASE"
}
repositories {
mavenCentral()
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
}
}
apply plugin: 'java'
apply plugin: 'org.springframework.boot'
dependencies {
compile("org.springframework.boot:spring-boot-starter-web") {
exclude module: "spring-boot-starter-tomcat"
}
compile("org.springframework.boot:spring-boot-starter-jetty")
compile("org.springframework.boot:spring-boot-starter-actuator")
compile project(':Libraries:Models')
testCompile 'junit:junit:4.12'
}
task wrapper(type: Wrapper) {
gradleVersion = '3.1'
}
}
/Project/Services/MyService
group 'nl.msegers.project.services.myservice'
version parent.version
jar {
baseName = 'myservice'
version = parent.version
}
repositories {
mavenCentral()
}
I'm trying to make build configuration of multimodule project.
My goal is to have configuration, which will build war-file and deploy it to Tomcat.
My project contains four subprojects. There are:
api-common
api-school
api-spo
api-odo
I'd like to have war with all of modules or just some of them (api-common must always be in war)
I've main build.gradle where I configure cargo plugin
apply plugin: 'idea'
apply plugin: 'com.bmuschko.cargo'
allprojects{
apply plugin: 'java'
group = 'ru.dnevnik.enrollment'
version = '2.0'
sourceCompatibility = 1.8
repositories {
mavenCentral()
mavenLocal()
}
}
dependencies {
testCompile group: 'junit', name: 'junit', version: '4.11'
}
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.bmuschko:gradle-cargo-plugin:2.1'
}
}
cargo {
containerId = 'tomcat7x'
deployable {
context = 'api'
file = file('enrollment-api\\build\\libs\\enrollment-api-1.0.war') //todo: bad practice
}
}
Enrollment-api project has build.gradle file as
apply plugin: 'war'
configurations {
full
odo
spo
school
}
dependencies {
compile project(':enrollment-api-common')
odo project(':enrollment-api-odo')
school project(':enrollment-api-school')
spo project(':enrollment-api-spo')
}
I don't understand how to use configurations to run for example
gradle cargoDeployRemote {someFlag}
to achive my goal
I followed this tutorial. This runs fine.
I would like to create a multiproject build with one project that contains this spring application. So I added this project to a subfolder called web of this multiproject build, added a settings.gradle file:
include 'web'
As well as a build.gradle file:
apply plugin: 'application'
mainClassName = "hello.Application"
jar {
baseName = 'VoPro'
}
dependencies {
compile project(':web')
}
However, when i run $ gradle build, i get the error:
Could not resolve all dependencies for configuration ':runtime'.
> Cannot resolve external dependency org.springframework.boot:spring-boot-starter-web: because no repositories are defined.
Required by:
:test:unspecified > test:web:unspecified
Why can't gradle find any repositories?
EDIT: The web subproject contains the following build.gradle file (like in the tutorial):
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:1.2.2.RELEASE")
}
}
apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'idea'
apply plugin: 'spring-boot'
jar {
baseName = 'gs-rest-service'
version = '0.1.0'
}
repositories {
mavenCentral()
}
dependencies {
compile("org.springframework.boot:spring-boot-starter-web")
testCompile("junit:junit")
}
task wrapper(type: Wrapper) {
gradleVersion = '1.11'
}
You should add a build.gradle file under the web project itself and configure appropriate repositories there. Or add a global build.gradle and the following piece of code in it:
allprojects {
repositories {
mavenCentral()
mavenLocal()
}
}
Basically the multimodule project should have the following structure
-- build.gradle // all projects configuration
-- settings.gradle //includes all modules
-- module1
-- build.gradle
-- module2
-- build.gradle
-- modulen
-- build.gradle
..
After discussion in comments:
You need to specify the dependency along with version, no idea why:
compile("org.springframework.boot:spring-boot-starter-web:1.2.2.RELEASE")