Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/loops/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
多模块Spring引导项目中的Gradle依赖插件_Gradle_Spring Boot_Dependency Management_Spring Boot Gradle Plugin - Fatal编程技术网

多模块Spring引导项目中的Gradle依赖插件

多模块Spring引导项目中的Gradle依赖插件,gradle,spring-boot,dependency-management,spring-boot-gradle-plugin,Gradle,Spring Boot,Dependency Management,Spring Boot Gradle Plugin,在使用Gradle插件的多模块项目中,正确的Gradle配置看起来像什么 我有以下项目设置: parent | + build.gradle | + alpha | | | + build.gradle | + beta | | | + build.gradle 父模块包含通用项目配置 alpha模块是一个我希望使用bom中指定的版本号导入依赖项的模块,但其结果是一个标准jar beta模块是一个依赖于alpha的模块,其结果是一个可执

在使用Gradle插件的多模块项目中,正确的Gradle配置看起来像什么

我有以下项目设置:

parent
  |
  + build.gradle
  |
  + alpha
  |   |
  |   + build.gradle
  |
  + beta
  |   |
  |   + build.gradle
  • 父模块包含通用项目配置
  • alpha
    模块是一个我希望使用bom中指定的版本号导入依赖项的模块,但其结果是一个标准jar
  • beta
    模块是一个依赖于
    alpha
    的模块,其结果是一个可执行的Spring引导jar文件(包括所有依赖项)。因此,这个项目既需要
    spring引导依赖项
    ,也需要
    spring引导
    插件
为了使Gradle文件保持干燥,我将通用模块脚本提取到父级的
build.Gradle
文件中

尝试使用下面的项目配置执行
$gradle build
,结果是:

> Plugin with id 'io.spring.dependency-management' not found.

父级渐变。构建

allprojects {
    group = "com.example"
    version '0.0.1-SNAPSHOT'

    ext {
        dependencyManagementPluginVersion = '0.5.3.RELEASE'
        springBootVersion = '1.3.0.RC1'
    }

    apply plugin: 'java'
    apply plugin: 'eclipse'
    apply plugin: 'idea'
}

subprojects {
    sourceCompatibility = 1.8
    targetCompatibility = 1.8

    buildscript {
        repositories {
            jcenter()
            maven { url "https://repo.spring.io/snapshot" }
            maven { url "https://repo.spring.io/milestone" }
        }
        dependencies {
            classpath("io.spring.gradle:dependency-management-plugin:${dependencyManagementPluginVersion}")
            classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
        }
    }

    apply plugin: 'io.spring.dependency-management'

    dependencyManagement {
        imports {
            mavenBom("org.springframework.boot:spring-boot-dependencies:${springBootVersion}")
//            mavenBom("org.springframework.boot:spring-boot-starter-parent:${springBootVersion}")
        }
    }
}
apply plugin: 'spring-boot'

dependencies {
    compile project(':alpha')
    compile('org.springframework.boot:spring-boot-starter')
    compile('org.springframework.boot:spring-boot-starter-web')
}
alpha build.gradle

dependencies {
    compile('org.springframework:spring-web')
}
beta gradle.build

allprojects {
    group = "com.example"
    version '0.0.1-SNAPSHOT'

    ext {
        dependencyManagementPluginVersion = '0.5.3.RELEASE'
        springBootVersion = '1.3.0.RC1'
    }

    apply plugin: 'java'
    apply plugin: 'eclipse'
    apply plugin: 'idea'
}

subprojects {
    sourceCompatibility = 1.8
    targetCompatibility = 1.8

    buildscript {
        repositories {
            jcenter()
            maven { url "https://repo.spring.io/snapshot" }
            maven { url "https://repo.spring.io/milestone" }
        }
        dependencies {
            classpath("io.spring.gradle:dependency-management-plugin:${dependencyManagementPluginVersion}")
            classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
        }
    }

    apply plugin: 'io.spring.dependency-management'

    dependencyManagement {
        imports {
            mavenBom("org.springframework.boot:spring-boot-dependencies:${springBootVersion}")
//            mavenBom("org.springframework.boot:spring-boot-starter-parent:${springBootVersion}")
        }
    }
}
apply plugin: 'spring-boot'

dependencies {
    compile project(':alpha')
    compile('org.springframework.boot:spring-boot-starter')
    compile('org.springframework.boot:spring-boot-starter-web')
}

评论:

  • spring boot 1.3.0.M1中
    spring boot
    插件的行为
  • 渐变版本:2.8
  • Spring Boot版本1.3.0.RC1

事实证明,
父级/build.gradle
应按以下方式重新排列:

buildscript {
    ext {
        dependencyManagementPluginVersion = '0.5.3.RELEASE'
        springBootVersion = '1.3.0.RC1'
    }
    repositories {
        jcenter()
        maven { url "https://repo.spring.io/snapshot" }
        maven { url "https://repo.spring.io/milestone" }
    }
    dependencies {
        classpath("io.spring.gradle:dependency-management-plugin:${dependencyManagementPluginVersion}")
        classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
    }
}

allprojects {
    group = "com.example"
    version '0.0.1-SNAPSHOT'

    apply plugin: 'java'
    apply plugin: 'eclipse'
    apply plugin: 'idea'
}

subprojects {
    sourceCompatibility = 1.8
    targetCompatibility = 1.8

    apply plugin: 'io.spring.dependency-management'

    dependencyManagement {
        imports {
            mavenBom("org.springframework.boot:spring-boot-dependencies:${springBootVersion}")
//          mavenBom("org.springframework.boot:spring-boot-starter-parent:${springBootVersion}")
        }
    }
}

问题在于子项目的
buildscript
块确实配置得很好,但是。。。在一个错误的地方。此
子项目
块与子项目相关,但将在声明的脚本中对其进行评估,并且没有声明它试图应用的插件的依赖项。

谢谢,但它并不完全有效。现在Gradle无法找到子模块的存储库:
>无法解析外部依赖项org.springframework.boot:spring-boot-dependencies:1.3.0.RC1,因为没有定义存储库。需要:com。示例:alpha:0.0.1-SNAPSHOT
存储库
复制到
所有项目
解决了这个问题,但是是否有一种方法可以一次性定义
存储库
,以便从
构建脚本
所有项目
都可以访问它?否:/,这些是独立的配置。它需要复制。仅供参考,
buildscript
适用于
build.gradle
,而不适用于其中的任何特定项目,因此您的发现并不令人惊讶。但是你的答案与你的问题所显示的不一样;根项目不再具有依赖管理功能。如果我的答案有帮助,请重新投票。@Opal对于延迟表示抱歉,我以为我已经接受了你的答案。我已经就此事写了一封信,请检查确认书。:-)谢谢,这正是我遇到的问题——为了帮助其他人搜索这个问题,我将添加:如果您天真地尝试:将插件“spring boot”应用到您的所有子项目(仅为了免费获得spring依赖关系管理),您将得到生成错误(至少我在windows下得到过),例如:任务执行失败:xxxxx:bootRepackage”。无法将“xxxxx.jar”重命名为“xxxxx.jar.original”@matsev,我刚刚注意到关于这篇文章的信息-看起来不错。谢谢你的提醒!