本文介绍了使用来自"flatDir"的插件和依赖项的Gradle构建的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果FlatDir中存在构建项目所需的所有jar(插件+依赖项),如何进行gradle构建?我的D驱动器中的"D:/path/to/local/directory"下具有所有必需的jar.现在,当我尝试进行gradle构建时,由于各种原因,它每次都会失败.需要帮助修复该问题(Gradle版本6.3).我的Build.gradle中的代码

How to make a gradle build if all the required jars to build the project (plugins+dependencies) are present in flatDir ? I have all the required jars in my D drive under "D:/path/to/local/directory". Now when I am trying to do a gradle build, it fails every time for different reasons. Need help in fixing the same (Gradle version 6.3). Code in my 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中的代码

Code in my settings.gradle

pluginManagement {
    flatDir {
        dirs 'D:/path/to/local/directory'
    }
}

推荐答案

经过几次尝试(Gradle6.3),我发现了如何从平面目录构建项目.您必须在flatDir信息库中拥有所有依赖项(以及传递性依赖项).我将所有jar放在我项目的名为"lib"的根文件夹内的单个目录中,并修改了build.gradle和settings.gradle,如下所示:build.gradle

I found out how to build a project from flat directory after some tries (Gradle6.3). You must have all the dependencies in the flatDir repository (Transitive dependencies as well). I kept all the jars in a single directory inside the root folder named "lib" of my project and modified the build.gradle and settings.gradle like below : 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

settings.gradle

pluginManagement {
    buildscript {
        repositories {
            flatDir {
                dirs 'lib'
            }
        }
        dependencies {
            classpath fileTree(dir: 'lib', include: '*.jar')
        }
    }
}
rootProject.name = 'gradleproj'

这篇关于使用来自"flatDir"的插件和依赖项的Gradle构建的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-18 15:28