3

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'
    }
}

Code in my settings.gradle:

pluginManagement {
    flatDir {
        dirs 'D:/path/to/local/directory'
    }
}
aSemy
  • 5,485
  • 2
  • 25
  • 51
Xerxis
  • 191
  • 1
  • 9

1 Answers1

4

I found out how to build a project from flat directory after some tries (Gradle 6.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

pluginManagement {
    buildscript {
        repositories {
            flatDir {
                dirs 'lib'
            }
        }
        dependencies {
            classpath fileTree(dir: 'lib', include: '*.jar')
        }
    }
}
rootProject.name = 'gradleproj'
aSemy
  • 5,485
  • 2
  • 25
  • 51
Xerxis
  • 191
  • 1
  • 9