带有子项目的Gradle项目由于打开文件而无法清理/构建最终子项目

问题描述

我需要从架构生成Java模型。我正在使用jsonSchema2Pojo,因为它似乎可以为我们提供最佳的表示形式(带有@pattern之类的注释)。问题在于这不会添加我们在工作中使用的某些特定注释。因此,我有一个Spring Boot应用程序,它在模型生成后运行,并对生成的类进行更新调整。接下来,我要基于生成的模型构建一个jar,以便我们可以包含该jar并拥有所有必需的模型,因为它们对于多个应用程序是通用的。

我目前正在使用多项目设置,但是由于我是新手,所以可以采用不同的方法

问题:我在create jar子项目上遇到IOException,因为它无法清理libs目录,因为某些东西已打开生成的jar文件

以下是详细信息:

+-> Main build.gradle
+---> generatemodels
+---> updatemodels
+---> create jar (this build.gradle is also in the directory/path where the models are)

这是build.gradles

settings.gradle

rootProject.name = 'consolidated-models'
include 'ConsolidatedModelGenerateJson'
include 'ConsolidatedModelUpdaterapplication'
include 'ConsolidatedModels'

主要build.gradle(构建脚本位于另一个目录中,如果需要可以添加,但是由于无法确定是否需要)

buildscript {
    ext {
        springBootVersion = '2.3.3.RELEASE'
        eliLogging = '3.0.0'
        cucumberVersion = '1.2.5'
        swaggerVersion = '2.9.2'
        lombokVersion = '1.18.12'
    }
    repositories {
        maven { url "https://mavenrepo.local.com/nexus/content/groups/public" }
        maven { url 'https://repo.gradle.org/gradle/libs-releases' }
    }
    dependencies {
        classpath "io.spring.gradle:dependency-management-plugin:1.0.9.RELEASE"
        classpath "org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}"
        classpath "org.sonarsource.scanner.gradle:sonarqube-gradle-plugin:2.7.1"

    }
}

allprojects {
    System.setProperty('org.gradle.color.error','RED')
    System.setProperty('org.gradle.color.failure','RED')
    System.setProperty('org.gradle.color.progressstatus','YELLOW')
    System.setProperty('org.gradle.color.success','GREEN')
}


subprojects {

    // Bring in repos
    buildscript { apply from: rootProject.file('buildscripts/repositories.gradle') }

    // Bring in plugins
    buildscript { apply from: rootProject.file('buildscripts/plugins.gradle') }

    sourceCompatibility = '1.8'
    targetCompatibility = '1.8'

    evaluationDependsOnChildren();

    // Bring in configurations
    buildscript { apply from: rootProject.file('buildscripts/configurations.gradle') }

    // Bring in dependency management
    buildscript { apply from: rootProject.file('buildscripts/dependencymanagement.gradle') }

    // Bring in dependenices
    buildscript { apply from: rootProject.file('buildscripts/dependencies.gradle') }

    // Bring in testing block
    buildscript { apply from: rootProject.file('buildscripts/testing.gradle') }


}

生成模型build.gradle

plugins {
    id 'com.github.eirnym.js2p' version '1.0'
}

repositories {
    maven { url "https://mavenrepo.local.com/nexus/content/groups/public" }
    maven { url "https://mavenrepo.local.com/nexus/content/repositories/releases/" }
    mavenCentral()
}

ext {
    sourceCompatibility = JavaVersion.VERSION_1_8
    targetCompatibility = JavaVersion.VERSION_1_8
}

dependencies {
    compile 'javax.validation:validation-api:1.1.0.CR2'
    compile 'com.fasterxml.jackson.core:jackson-databind:2.9.7'
    compile 'joda-time:joda-time:2.2'
    compile 'me.itzg:jsonschema2pojo-rules-bettermaps:1.0.2'

}

bootJar {
    enabled = false
    baseName = 'ConsolidatedModelGenerateJson'
}
jar {
    baseName = 'ConsolidatedModelGenerateJson'
}

jsonSchema2Pojo {

<<<in the interest of space I have removed the settings since this works,if we need it I can add it back>>>

}

更新模型build.gradle(编译并运行的Spring Boot应用程序,以便它可以在构建过程中以单个命令的思想更新模型)

buildscript {
    ext {
        springBootVersion = '2.3.3.RELEASE'
        eliLogging = '3.0.0'
        cucumberVersion = '1.2.5'
        swaggerVersion = '2.9.2'
        lombokVersion = '1.18.12'
    }
    repositories {
        maven { url "https://mavenrepo.local.com/nexus/content/groups/public" }
        maven { url "https://mavenrepo.local.com/nexus/content/repositories/releases/" }
        mavenCentral()
    }
    dependencies {
        classpath "io.spring.gradle:dependency-management-plugin:1.0.10.RELEASE"
        classpath "org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}"
        classpath "org.sonarsource.scanner.gradle:sonarqube-gradle-plugin:2.7.1"

    }
}

plugins {
    id 'org.springframework.boot'
    id 'io.spring.dependency-management'
    id 'java-gradle-plugin'
    id 'idea'
    id 'eclipse'
    id 'jacoco'
    id 'maven-publish'
    id 'java-library'
    id 'groovy'
}

ext {
    sourceCompatibility = JavaVersion.VERSION_1_8
    targetCompatibility = JavaVersion.VERSION_1_8
    springBootVersion = '2.3.3.RELEASE'
    eliLogging = '3.0.0'
    cucumberVersion = '1.2.5'
    swaggerVersion = '2.9.2'
    lombokVersion = '1.18.12'
    powerMockVersion = '2.0.7'
}

evaluationDependsOn(':ConsolidatedModelGenerateJson')


allprojects {
    System.setProperty('org.gradle.color.error','GREEN')
}

repositories {
    maven { url "https://mavenrepo.local.com/nexus/content/groups/public" }
    maven { url "https://mavenrepo.local.com/nexus/content/repositories/releases/" }
    mavenCentral()
}


sourceCompatibility = '1.8'
targetCompatibility = '1.8'


// Bring in dependency management
dependencyManagement {
    imports {
        mavenBom "io.pivotal.spring.cloud:spring-cloud-services-dependencies:2.1.4.RELEASE"
        mavenBom "org.springframework.cloud:spring-cloud-dependencies:Greenwich.SR3"
        mavenBom "org.springframework.boot:spring-boot-dependencies:${springBootVersion}"
    }
}

// Bring in dependenices

// Implementations Lists
List springBoot = [
        "org.springframework.boot:spring-boot-starter:${springBootVersion}","org.springframework.boot:spring-boot-configuration-processor:${springBootVersion}","org.springframework.boot:spring-boot-starter-web:${springBootVersion}","org.springframework.boot:spring-boot-starter-webflux:${springBootVersion}","org.springframework.boot:spring-boot-starter-actuator:${springBootVersion}","org.springframework.boot:spring-boot-starter-logging:${springBootVersion}","org.springframework.boot:spring-boot-starter-log4j2:${springBootVersion}","org.springframework.boot:spring-boot-starter-security:${springBootVersion}",]
List springWeb = [
        "org.springframework.ws:spring-ws-core:2.4.3.RELEASE",]
List springCloud = [
        "io.pivotal.spring.cloud:spring-cloud-services-starter-config-client"
]
List apache = [
        "org.apache.httpcomponents:httpclient",]
List gradletooling = [
        "org.gradle:gradle-tooling-api:4.3",]
List javax = [
        "javax.jdo:jdo-api:3.1","javax.persistence:javax.persistence-api:2.2","javax.validation:validation-api:2.0.0.Final","javax.xml.bind:jaxb-api:2.3.1",]
List googleCode = [
        "com.google.guava:guava:28.2-jre","com.googlecode.json-simple:json-simple:1.1.1",]
List swagger = [
        "io.springfox:springfox-swagger2:${swaggerVersion}",]
List lombok = [
        "org.projectlombok:lombok:${lombokVersion}",]
List restLogging = [
        // "org.hobsoft.spring:spring-rest-template-logger:2.0.0",]
List swaggerCode = [
        "io.swagger.core.v3:swagger-jaxrs2:2.1.2","io.swagger.core.v3:swagger-jaxrs2-servlet-initializer-v2:2.1.2",]
List classIndexList = [
        "org.atteo.classindex:classindex:3.4",]
List springBootAnnotation = [
        "org.springframework.boot:spring-boot-configuration-processor:${springBootVersion}",]
List jsonSchema = [
        "joda-time:joda-time:2.2","me.itzg:jsonschema2pojo-rules-bettermaps:1.0.2","com.fasterxml.jackson.core:jackson-databind:2.11.2","com.fasterxml.jackson.core:jackson-annotations:2.11.2","com.fasterxml.jackson.core:jackson-core:2.11.2"
]


// Test Implementations Lists
List springTest = [
        "org.springframework.boot:spring-boot-starter-test:${springBootVersion}",]
List powerMock = [
        "org.powermock:powermock-core:${powerMockVersion}","org.powermock:powermock-api-mockito2:${powerMockVersion}","org.powermock:powermock-module-junit4:${powerMockVersion}",]

List cucumber = [
        "info.cukes:cucumber-jvm:${cucumberVersion}","info.cukes:cucumber-core:${cucumberVersion}","info.cukes:cucumber-java:${cucumberVersion}","info.cukes:cucumber-junit:${cucumberVersion}","info.cukes:cucumber-spring:${cucumberVersion}","io.rest-assured:rest-assured:3.0.0",]
List reactor = [
        "io.projectreactor:reactor-test",]

def commonDependenciesToExclude = {

}


dependencies {

    implementation(project(":ConsolidatedModelGenerateJson"))

    // Implementation
    implementation springBoot
    implementation springWeb
    implementation apache
    implementation gradletooling
    implementation javax
    implementation googleCode
    implementation swagger
    implementation lombok
    implementation powerMock
    implementation restLogging
    implementation classIndexList
    implementation springCloud

    implementation swaggerCode

    // Compile only
    testCompile cucumber

    compile jsonSchema

    // Lombok
    compileOnly compileOnlyList


    // Annotations processor
    annotationProcessor lombok
    annotationProcessor classIndexList
    annotationProcessor springBootAnnotation


    // Test Implementation
    testImplementation springTest
    testImplementation lombok
    testImplementation reactor
    testImplementation('org.springframework.boot:spring-boot-starter-test') {
        exclude group: 'org.junit.vintage',module: 'junit-vintage-engine'
    }

    // Test Annotation
    testAnnotationProcessor lombok

}



bootJar {
    enabled = true
    baseName = 'ConsolidatedModelUpdaterapplication'
}
jar {
    baseName = 'ConsolidatedModelUpdaterapplication'
}

sourceSets {
    main {
        java {
            srcDirs = ["./src/main/java"]
        }
    }
    test {
        java {
            srcDirs = ["./src/test/java"]
        }
    }
}

tasks.register("bootRunDev") {
    group = "application"
    description = "Runs the Spring Boot application with the dev profile"
    doFirst {
        tasks.bootRun.configure {
            systemProperty("spring.profiles.active","dev")
        }
    }
    finalizedBy("bootRun")
}

build.dependsOn bootRunDev

构建jar build.gradle(在生成文件所在的子项目中)

buildscript {
    ext {
        springBootVersion = '2.3.3.RELEASE'
        eliLogging = '3.0.0'
        cucumberVersion = '1.2.5'
        swaggerVersion = '2.9.2'
        lombokVersion = '1.18.12'
    }
    repositories {
        maven { url "https://mavenrepo.local.com/nexus/content/groups/public" }
        maven { url "https://mavenrepo.local.com/nexus/content/repositories/releases/" }
        mavenCentral()
    }
    dependencies {
        classpath "io.spring.gradle:dependency-management-plugin:1.0.10.RELEASE"
        classpath "org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}"
        classpath "org.sonarsource.scanner.gradle:sonarqube-gradle-plugin:2.7.1"
    }
}

plugins {
    id 'java'
    id 'org.springframework.boot'
    id 'io.spring.dependency-management'
    id 'java-gradle-plugin'
    id 'idea'
    id 'eclipse'
    id 'jacoco'
    id 'maven-publish'
    id 'java-library'
    id 'groovy'
}

ext {
    sourceCompatibility = JavaVersion.VERSION_1_8
    targetCompatibility = JavaVersion.VERSION_1_8
    lombokVersion = '1.18.12'
}

evaluationDependsOn(':ConsolidatedModelUpdaterapplication')
//clean.dependsOn ':ConsolidatedModelUpdaterapplication:bootRunDev'
build.dependsOn ':ConsolidatedModelUpdaterapplication:bootRunDev'
jar.dependsOn ':ConsolidatedModelUpdaterapplication:bootRunDev'

allprojects {
    System.setProperty('org.gradle.color.error','GREEN')
}

repositories {
    maven { url "https://mavenrepo.local.com/nexus/content/groups/public" }
    maven { url "https://mavenrepo.local.com/nexus/content/repositories/releases/" }
    mavenCentral()
}


sourceCompatibility = '1.8'
targetCompatibility = '1.8'



// Bring in dependency management
dependencyManagement {
    imports {
        mavenBom "io.pivotal.spring.cloud:spring-cloud-services-dependencies:2.1.4.RELEASE"
        mavenBom "org.springframework.cloud:spring-cloud-dependencies:Greenwich.SR3"
        mavenBom "org.springframework.boot:spring-boot-dependencies:${springBootVersion}"
    }
}

// Bring in dependenices

List lombok = [
        "org.projectlombok:lombok:${lombokVersion}","com.fasterxml.jackson.core:jackson-core:2.11.2"
]


dependencies {

    implementation(project(":ConsolidatedModelGenerateJson"))
    implementation(project(":ConsolidatedModelUpdaterapplication"))

    // Implementation
    implementation lombok

    compile jsonSchema

    // Annotations processor
    annotationProcessor lombok


    // Test Implementation
    testImplementation('org.springframework.boot:spring-boot-starter-test') {
        exclude group: 'org.junit.vintage',module: 'junit-vintage-engine'
    }

    // Test Annotation
    testAnnotationProcessor lombok

}



bootJar {
    enabled = false
    baseName = 'ConsolidatedModels'
}
jar {
    enabled = true
    baseName = 'ConsolidatedModels'
}

sourceSets {
    main {
        java {
            srcDirs = ["./src/main/java"]
        }
    }
    test {
        java {
            srcDirs = ["./src/test/java"]
        }
    }
}

这是我运行“ gradle clean build”的例外情况

FAILURE: Build Failed with an exception.

* What went wrong:
Execution Failed for task ':ConsolidatedModels:clean'.
> java.io.IOException: Unable to delete directory '.\ConsolidatedModels\build'
    Failed to delete some children. This might happen because a process has files open or has its working directory set in the target directory.
    - .\ConsolidatedModels\build\libs\ConsolidatedModels.jar
    - .\ConsolidatedModels\build\libs

有什么办法解决此问题吗? 另外,如果您有一个如何使它与众不同的想法(例如一个项目之类的东西),我也乐于接受。

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...