我刚接触Gradle.我正在尝试在STS中创建spring boot gradle mutli项目,但我不知道如何创建.我能够创建单个项目.所以请告诉我如何创建多个项目。
Root proect:nn-backend
build.gradle:
plugins {
id 'org.springframework.boot' version '2.1.8.RELEASE'
id 'io.spring.dependency-management' version '1.0.8.RELEASE'
id 'java'
}
group = 'com.nn'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '1.8'
repositories {
mavenCentral()
maven { url "https://repo.spring.io/snapshot" }
maven { url "https://repo.spring.io/milestone" }
}
allprojects {
group = 'com.nn'
//version = rootProject.version
//sourceCompatibility = 1.8
apply plugin: 'application'
apply plugin: 'java'
apply plugin: 'jacoco'
apply plugin: 'maven'
apply plugin: 'io.spring.dependency-management'
apply plugin: 'org.springframework.boot'
mainClassName = 'com.cc.CcAdminApplication'
version = rootProject.version
ext {
set('springCloudVersion', 'Greenwich.RC2')
}
configurations {
provided
compile.extendsFrom provided
compile.exclude module: 'log4j-slf4j-impl'
}
repositories {
mavenCentral()
maven { url "http://repo.spring.io/release" }
maven { url "http://repo.spring.io/milestone" }
maven { url "http://repo.spring.io/snapshot" }
maven { url "http://repo.maven.apache.org/maven2" }
maven { url 'https://repo.spring.io/libs-release' }
}
dependencies {
compile('org.springframework.boot:spring-boot-starter-actuator')
compile('org.springframework.boot:spring-boot-starter-log4j2')
testCompile('org.springframework.boot:spring-boot-starter-test')
compile('org.springframework.boot:spring-boot-starter-logging')
compile('org.apache.commons:commons-lang3:3.6')
provided group: 'org.projectlombok', name: 'lombok', version: '1.16.20'
compile group: 'com.vaadin.external.google', name: 'android-json', version: '0.0.20131108.vaadin1'
}
}
settings.gradle:
rootProject.name = 'nn-backend'
include ':nn-model'
include ':nn-admin'
include ':nn-common'
include ':nn-filters'
子项目:nn-公共build.gradle:
plugins {
id 'org.springframework.boot' version '2.1.8.RELEASE'
id 'io.spring.dependency-management' version '1.0.8.RELEASE'
id 'java'
}
group = 'com.nn'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '1.8'
repositories {
mavenCentral()
}
dependencies {
implementation 'org.springframework.boot:spring-boot-starter'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
}
子项目:nn-filters build.gradle:
plugins {
id 'org.springframework.boot' version '2.1.8.RELEASE'
id 'io.spring.dependency-management' version '1.0.8.RELEASE'
id 'java'
}
group = 'com.nn'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '1.8'
repositories {
mavenCentral()
}
dependencies {
compile project(':nn-common')
implementation 'org.springframework.boot:spring-boot-starter'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
}
错误:
发布于 2019-09-15 15:20:10
您应该首先定义root project
的build.gradle应具有以下配置:
build.gradle
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
}
}
allprojects {
repositories {
mavenCentral()
maven { url "http://repo.spring.io/milestone" }
}
apply plugin: 'java'
apply plugin: 'org.springframework.boot'
apply plugin: 'io.spring.dependency-management'
group = projectGroup
version = projectVersion
sourceCompatibility = javaVersion
dependencies {
// Here add the dependencies shared for each subproject.
compile('org.springframework.boot:spring-boot-autoconfigure')
compile('org.springframework.boot:spring-boot-starter')
compile('org.springframework.boot:spring-boot-starter-web')
// Here the the dependecies shared for testing
testCompile('org.springframework.boot:spring-boot-starter-test')
}
dependencyManagement {
imports {
mavenBom "org.springframework.cloud:spring-cloud-dependencies:${springCloudVersion}"
}
}
}
gradle.properties
javaVersion=1.8
projectGroup = com.example
projectName = project-name
projectVersion = 0.1-SNAPSHOT
springBootVersion = 2.0.0.RELEASE
springCloudVersion = Finchley.RELEASE
settings.gradle
rootProject.name = 'project-name'
include 'sub-project-1', 'sub-project-2', ..
让我们来定义sub-project-1的设置
build.gradle
bootJar {
mainClassName = 'com.example.sub-project-1.Application'
}
基本上,这将是多项目gradle的settings/properties
。sub-project-1
的最后一个build.gradle共享了allproject
body内部的所有依赖项。
https://stackoverflow.com/questions/57939086
复制相似问题