我正在使用gradle(4.7版)来编译具有多模块的项目(Java 1.8):
./gradlew -p web -x test build
其中一个没有dist jar,另一个有问题,编译输出的正常dir结构是什么?
--build
----classes
----libs
----tmp
和异常的目录结构:
--build
----classes
----tmp
这是build.gradle(异常模块):
project(":monitor-business") {
description = "business"
dependencies {
api project(':data')
api project(':common')
implementation('org.springframework.boot:spring-boot-starter-web')
}
}
PS:所有模块都不生成libs文件夹,libs是缓存。为什么模块不生成dis jar文件,如何配置gradle项目。这是项目的完整配置:
group 'dolphin'
version '1.0-SNAPSHOT'
buildscript {
ext {
springBootVersion = '2.1.3.RELEASE'
springVersion = '4.3.7.RELEASE'
springfoxVersion = '2.6.1'
jacksonVersion = '2.8.7'
lombokVersion = '1.16.14'
}
ext['tomcat.version'] = '9.0.16'
repositories {
mavenCentral()
jcenter{
url 'http://jcenter.bintray.com'
}
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
}
}
def getVersionCode() {
def versionFile = file("$rootDir/version.properties")
if (!versionFile.canRead()) {
throw new GradleException("Could not find version.properties!")
}
def versionProps = new Properties()
versionProps.load(new FileInputStream(versionFile))
def versionCode = versionProps['VERSION'].toString()
return versionCode
}
repositories {
mavenCentral()
}
allprojects {
apply plugin: 'java'
apply plugin: 'java-library'
apply plugin: 'org.springframework.boot'
apply plugin: 'io.spring.dependency-management'
repositories {
mavenCentral()
}
}
task wrapper(type: Wrapper) {
description = 'Generates gradlew[.bat] scripts'
gradleVersion = '4.7'
}
project(":common") {
description = ''
dependencies {
api("org.springframework:spring-context:" + springVersion)
api("commons-codec:commons-codec:1.10")
api("org.apache.tomcat:tomcat-juli:" + property('tomcat.version'))
api 'org.springframework.boot:spring-boot-starter-web'
api group: 'io.swagger', name: 'swagger-annotations', version: '1.5.20'
api("org.projectlombok:lombok:${lombokVersion}")
api group: 'org.apache.commons', name: 'commons-lang3', version: '3.5'
api group: 'org.mybatis.spring.boot', name: 'mybatis-spring-boot-starter', version: '1.3.0'
api group: 'org.mybatis', name: 'mybatis', version: '3.4.4'
api group: 'org.mybatis', name: 'mybatis-typehandlers-jsr310', version: '1.0.2'
}
}
project(":composite") {
description = 'dolphin-composite'
dependencies {
implementation project(":monitor-business")
api project(":data")
implementation("org.springframework:spring-context:" + springVersion)
}
}
project(":web") {
description = "web"
archivesBaseName = "dolphin-web-" + getVersionCode()
jar {
// Will include every single one of your dependencies, project or not
from {
configurations.runtimeClasspath.collect { it.isDirectory() ? it : zipTree(it) }
}
}
dependencies {
api project(':monitor-business')
api project(':api')
api project(':common')
api project(':data')
api project(':composite')
implementation("com.zaxxer:HikariCP:2.6.0")
api("org.mybatis:mybatis-spring:1.3.0")
implementation("mysql:mysql-connector-java:5.1.24")
implementation("org.springframework.boot:spring-boot-starter-web")
implementation("org.springframework.boot:spring-boot-starter")
implementation("io.springfox:springfox-swagger2:2.9.2")
implementation("io.springfox:springfox-swagger-ui:2.9.2")
implementation group: 'org.apache.tomcat', name: 'tomcat-juli', version: property('tomcat.version')
implementation("org.projectlombok:lombok:1.16.14")
implementation group: 'org.apache.commons', name: 'commons-lang3', version: '3.5'
implementation group: 'org.slf4j', name: 'slf4j-api', version: '1.7.24'
implementation group: 'org.mybatis', name: 'mybatis', version: '3.4.2'
implementation group: 'org.mybatis', name: 'mybatis-typehandlers-jsr310', version: '1.0.2'
testCompile group: 'junit', name: 'junit', version: '4.12'
}
}
project(":monitor-business") {
description = "business"
dependencies {
api project(':data')
api project(':common')
implementation('org.springframework.boot:spring-boot-starter-web')
}
}
project(":data") {
description = "data"
dependencies {
api project(':common')
api("org.projectlombok:lombok:${lombokVersion}")
implementation("com.zaxxer:HikariCP:2.6.0")
implementation group: 'org.postgresql', name: 'postgresql', version: '42.1.4'
api("org.hibernate:hibernate-validator:5.2.4.Final")
api("org.mybatis.spring.boot:mybatis-spring-boot-starter:1.1.1")
api("org.apache.commons:commons-lang3:3.5")
api group: 'org.springframework', name: 'spring-jdbc', version: '5.1.5.RELEASE'
api group: 'org.slf4j', name: 'slf4j-api', version: '1.7.24'
api group: 'org.mybatis', name: 'mybatis', version: '3.4.2'
api group: 'org.mybatis', name: 'mybatis-typehandlers-jsr310', version: '1.0.2'
testCompile group: 'junit', name: 'junit', version: '4.11'
api("com.fasterxml.jackson.datatype:jackson-datatype-jsr310:$jacksonVersion")
}
}
PS:我的问题就像这样的备忘录:https://discuss.gradle.org/t/gradle-4-x-jar-is-not-generated/24773
我已经解决了,但是不知道为什么。...
答案 0 :(得分:0)
要解决此问题,请使用以下命令来构建项目(它将生成libs文件夹和jar文件):
./gradlew -p web -x test -x jar build
版本版本:4.7。(5.3版不起作用)