Gradle configuration for Academy Plugin using external libraries

已回答

I just stumbled about the ability to create courses with IntelliJ. Looks like a nice method to share knowledge, so I gave it a try to create a course for some JPA lessons I learnt in the last months.

For that I need to use some dependencies, but I can't wrap my head around the gradle configuration within the course.

I need to add the dependencies for 'org.springframework.boot:spring-boot-starter-data-jpa' to all lessons/tasks of the course, but well, I don't get it after 1h of  playing around. 

Any ideas?
Are there examples of courses using external dependencies (couldn't find any)?

Settings for needed dependencies within the main project, with gradle build errors for the build script at the end.

How can I get these dependecies in all sub-projects (taks)?

build.gradle of the “course” with build-errors

buildscript {
    repositories {
        mavenCentral()
    }
}

plugins {
    id 'java'
    id 'org.springframework.boot' version '3.2.2'
    id 'io.spring.dependency-management' version '1.1.4'
}

dependencies {
    implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
    runtimeOnly 'com.h2database:h2'
    testImplementation 'org.springframework.boot:spring-boot-starter-test'
}

repositories {
    mavenCentral()
}

def printOutput(def output) {
    return tasks.create("printOutput") {
        println "#educational_plugin_checker_version 1"
        def separator = System.lineSeparator()
        def lines = output.toString().split("(?<=${separator})|(?=${separator})")
        for (line in lines) {
            println "#educational_plugin" + line
        }
    }
}

subprojects {
    apply plugin: 'application'
    apply plugin: 'java'
    // playing around
    apply plugin: 'org.springframework.boot'
    apply plugin: 'io.spring.dependency-management'

    sourceCompatibility = 1.8

    repositories {
        mavenCentral()
    }

    dependencies {
    // playing around
        implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
        runtimeOnly 'com.h2database:h2'
        testImplementation 'org.springframework.boot:spring-boot-starter-test'
        implementation group: 'junit', name: 'junit', version: '4.12'
    }

    sourceSets {
        main {
            java.srcDir 'src'
        }
        test {
            java.srcDir 'test'
        }
    }

    mainClassName = project.hasProperty("mainClass") ? project.getProperty("mainClass") : ""

    if (project.hasProperty("educationalRun") && "true".equalsIgnoreCase(project.getProperty("educationalRun"))) {
        def runOutput = new ByteArrayOutputStream()
        tasks.run.setStandardOutput(runOutput)
        tasks.run.doLast { printOutput(runOutput) }
    }
}

project(':util') {
    dependencies {
        implementation group: 'junit', name: 'junit', version: '4.12'
    }
}

configure(subprojects.findAll { it.name != 'util' }) {
    dependencies {
        implementation project(':util').sourceSets.main.output
        testImplementation project(':util').sourceSets.test.output
    }
}

 

0
正式评论

Hi, thank you for contacting us! Could you please try using this build.gradle with your course? Please let me know if that helps.

请先登录再写评论。