Gradle 使用来自 "flatDir" 的插件和依赖项构建
Gradle build using plugins and dependencies from "flatDir"
如果构建项目所需的所有 jar(插件+依赖项)都在 flatDir 中,如何进行 gradle 构建?我的 D 盘 "D:/path/to/local/directory" 下有所有需要的 jar。现在,当我尝试进行 gradle 构建时,每次都会因不同原因而失败。在修复相同问题时需要帮助(Gradle 6.3 版)。我的 Build.gradle
中的代码
buildscript {
repositories {
// If you want to use a (flat) filesystem directory as a repository
flatDir {
dirs 'D:/path/to/local/directory'
}
}
}
plugins {
id "jacoco"
id 'org.springframework.boot' version '2.2.6.RELEASE'
id 'io.spring.dependency-management' version '1.0.9.RELEASE'
id 'java'
id 'war'
id "org.sonarqube" version "2.8"
}
dependencies {
implementation 'org.springframework.boot:spring-boot-starter-web'
implementation 'org.springframework.boot:spring-boot-starter-web-services'
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
implementation 'wsdl4j:wsdl4j:1.6.3'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
testImplementation 'org.springframework.ws:spring-ws-test'
testImplementation 'org.apache.httpcomponents:httpclient:4.5.9'
testImplementation 'com.h2database:h2:1.4.199'
}
bootWar {
baseName = 'web-service'
version = '1.0.0'
}
jacocoTestReport {
reports {
xml.enabled true
}
}
sonarqube {
properties {
property 'sonar.projectName', 'Sonar-Gradle-Integration'
}
}
我的代码 settings.gradle
pluginManagement {
flatDir {
dirs 'D:/path/to/local/directory'
}
}
经过一些尝试,我发现了如何从平面目录构建项目 (Gradle6.3)。您必须在 flatDir 存储库中拥有所有依赖项(以及传递依赖项)。我将所有 jar 保存在我项目的名为 "lib" 的根文件夹内的一个目录中,并修改了 build.gradle 和 settings.gradle,如下所示:build.gradle
plugins {
id "org.sonarqube"
id "jacoco"
id 'java'
id 'war'
}
group = 'com.example'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '1.8'
repositories {
// If you want to use a (flat) filesystem directory as a repository
flatDir {
dirs 'lib'
}
}
dependencies {
implementation fileTree(dir: 'lib', include: '*.jar')
testImplementation fileTree(dir: 'lib', include: '*.jar')
}
jacocoTestReport {
reports {
xml.enabled true
}
}
settings.gradle
pluginManagement {
buildscript {
repositories {
flatDir {
dirs 'lib'
}
}
dependencies {
classpath fileTree(dir: 'lib', include: '*.jar')
}
}
}
rootProject.name = 'gradleproj'
如果构建项目所需的所有 jar(插件+依赖项)都在 flatDir 中,如何进行 gradle 构建?我的 D 盘 "D:/path/to/local/directory" 下有所有需要的 jar。现在,当我尝试进行 gradle 构建时,每次都会因不同原因而失败。在修复相同问题时需要帮助(Gradle 6.3 版)。我的 Build.gradle
中的代码buildscript {
repositories {
// If you want to use a (flat) filesystem directory as a repository
flatDir {
dirs 'D:/path/to/local/directory'
}
}
}
plugins {
id "jacoco"
id 'org.springframework.boot' version '2.2.6.RELEASE'
id 'io.spring.dependency-management' version '1.0.9.RELEASE'
id 'java'
id 'war'
id "org.sonarqube" version "2.8"
}
dependencies {
implementation 'org.springframework.boot:spring-boot-starter-web'
implementation 'org.springframework.boot:spring-boot-starter-web-services'
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
implementation 'wsdl4j:wsdl4j:1.6.3'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
testImplementation 'org.springframework.ws:spring-ws-test'
testImplementation 'org.apache.httpcomponents:httpclient:4.5.9'
testImplementation 'com.h2database:h2:1.4.199'
}
bootWar {
baseName = 'web-service'
version = '1.0.0'
}
jacocoTestReport {
reports {
xml.enabled true
}
}
sonarqube {
properties {
property 'sonar.projectName', 'Sonar-Gradle-Integration'
}
}
我的代码 settings.gradle
pluginManagement {
flatDir {
dirs 'D:/path/to/local/directory'
}
}
经过一些尝试,我发现了如何从平面目录构建项目 (Gradle6.3)。您必须在 flatDir 存储库中拥有所有依赖项(以及传递依赖项)。我将所有 jar 保存在我项目的名为 "lib" 的根文件夹内的一个目录中,并修改了 build.gradle 和 settings.gradle,如下所示:build.gradle
plugins {
id "org.sonarqube"
id "jacoco"
id 'java'
id 'war'
}
group = 'com.example'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '1.8'
repositories {
// If you want to use a (flat) filesystem directory as a repository
flatDir {
dirs 'lib'
}
}
dependencies {
implementation fileTree(dir: 'lib', include: '*.jar')
testImplementation fileTree(dir: 'lib', include: '*.jar')
}
jacocoTestReport {
reports {
xml.enabled true
}
}
settings.gradle
pluginManagement {
buildscript {
repositories {
flatDir {
dirs 'lib'
}
}
dependencies {
classpath fileTree(dir: 'lib', include: '*.jar')
}
}
}
rootProject.name = 'gradleproj'