Java JHipster格式中的渐变依赖项”;groupId:artifact";

Java JHipster格式中的渐变依赖项”;groupId:artifact";,java,gradle,jhipster,Java,Gradle,Jhipster,我在这里发帖是为了了解如何处理Gradle依赖项,特别是我无法将其中一些复制到我在JH项目中创建的Gradle子模块中 例如,以下内容在渐变子模块中不起作用 compile "junit:junit" 错误是 Could not resolve: junit:junit 然而,这部经典作品抄袭自伟大的作品 compile group: 'junit', name: 'junit', version: '4.12' 一些附加信息:我正在创建一个子模块,其中包含一组与测试相关的类,主要是从An

我在这里发帖是为了了解如何处理Gradle依赖项,特别是我无法将其中一些复制到我在JH项目中创建的Gradle子模块中

例如,以下内容在渐变子模块中不起作用

compile "junit:junit"
错误是

Could not resolve: junit:junit
然而,这部经典作品抄袭自伟大的作品

compile group: 'junit', name: 'junit', version: '4.12'
一些附加信息:我正在创建一个子模块,其中包含一组与测试相关的类,主要是从Ant world的另一个项目复制的大量定制Hamcrest匹配器。最初的项目有很多杂乱无章的代码,所以现在我正在重构成一个独立的Gradle模块。
testlib
模块应取决于测试框架,并包含编写良好测试所需的所有内容。它可以与您用来编写自己的基于spring的测试的
spring测试项目相比较

目前,gradle文件看起来像

plugins {
    id "java"
}
configurations {
    providedRuntime
    implementation.exclude module: "spring-boot-starter-tomcat"
}
repositories {
    mavenLocal()
    mavenCentral()
    jcenter()
}
group 'org.example' //different from com.acme of super-project
version '0.0.1-SNAPSHOT'
sourceCompatibility = 1.8
dependencies {
    compile group: 'org.assertj', name: 'assertj-core', version: '3.13.2'
    compile group: 'org.junit.jupiter', name: 'junit-jupiter-api', version: '5.5.2'
    compile group: 'org.hamcrest', name: 'hamcrest', version: '2.1'
    compile group: 'org.mockito', name: 'mockito-core', version: '3.0.0'
    compile group: 'org.springframework.boot', name: 'spring-boot', version: spring_boot_version
    compile "junit:junit" //Fails
}
dependencies {
    // import JHipster dependencies BOM
    implementation platform("io.github.jhipster:jhipster-dependencies:${jhipster_dependencies_version}")

    compile "org.assertj:assertj-core"
    compile "org.junit.jupiter:junit-jupiter-api"
    compile "org.hamcrest:hamcrest"
    compile "org.mockito:mockito-core"
    compile "org.springframework.boot:spring-boot"
    compile "junit:junit"
}
问题: 因此,问题分为两部分:

  • 为什么
    作用域“orgId:name”
    语法在JHipster生成的模块中有效,而在子模块中无效?它是标准Gradle语法的一部分吗
  • 为什么这在子模块中不起作用?JHipster是否应用自定义插件来应用明显缺失的正确版本号?我如何在一个子模块中执行相同的操作,该子模块应该只包含Java库代码

  • 关于杰普斯特,更多的调查会有所帮助。据介绍,Gradle中有一个叫做物料清单项目的技巧,所以

    TL;博士 将以下内容添加到子项目中

    // import JHipster dependencies BOM
    implementation platform("io.github.jhipster:jhipster-dependencies:${jhipster_dependencies_version}")
    
    所以整个街区看起来像

    plugins {
        id "java"
    }
    configurations {
        providedRuntime
        implementation.exclude module: "spring-boot-starter-tomcat"
    }
    repositories {
        mavenLocal()
        mavenCentral()
        jcenter()
    }
    group 'org.example' //different from com.acme of super-project
    version '0.0.1-SNAPSHOT'
    sourceCompatibility = 1.8
    dependencies {
        compile group: 'org.assertj', name: 'assertj-core', version: '3.13.2'
        compile group: 'org.junit.jupiter', name: 'junit-jupiter-api', version: '5.5.2'
        compile group: 'org.hamcrest', name: 'hamcrest', version: '2.1'
        compile group: 'org.mockito', name: 'mockito-core', version: '3.0.0'
        compile group: 'org.springframework.boot', name: 'spring-boot', version: spring_boot_version
        compile "junit:junit" //Fails
    }
    
    dependencies {
        // import JHipster dependencies BOM
        implementation platform("io.github.jhipster:jhipster-dependencies:${jhipster_dependencies_version}")
    
        compile "org.assertj:assertj-core"
        compile "org.junit.jupiter:junit-jupiter-api"
        compile "org.hamcrest:hamcrest"
        compile "org.mockito:mockito-core"
        compile "org.springframework.boot:spring-boot"
        compile "junit:junit"
    }
    
    长话短说
    也许将来我会更了解格雷德尔。或者仅仅bom定义了要使用的第三方依赖项的版本(除其他外),因此您可以省略显式版本。如果不使用bom,您也可以编写
    编译“junit:junit:4.12”
    ,但请记住,jhipster默认情况下已将junit5用于所有测试

    关于bom的导入,您可以按照您的建议进行,或者尝试将该依赖关系应用于主gradle文件中的所有gradle子项目。

    可能相关: