首页 文章

Spring平台用于Gradle多模块项目

提问于
浏览
0

我有一个多模块gradle项目 .

Root有以下模块:核心,app(依赖于核心),web(依赖于app,核心)

来自https://plugins.gradle.org/plugin/io.spring.dependency-management

我用过

plugins {  id "io.spring.dependency-management" version "0.5.4.RELEASE" }

 dependencyManagement {
  imports { 
     mavenBom 'io.spring.platform:platform-bom:+' // 2.0.1.RELEASE
   }
  }

在核心的build.gradle里面 .

当我触发时

gradle clean build

从root命令提示符,核心jar已成功构建,但app failed 解析了依赖项的版本 .

common.gradle 在根目录中

repositories {
    mavenCentral()
    maven { url "http://repo.grails.org/grails/repo/" }
    // mavenLocal()
}

核心 build.gradle

plugins {
   id "io.spring.dependency-management" version "0.5.4.RELEASE"
}

apply from: '../common.gradle'
apply plugin: 'java'

dependencyManagement {
   imports {
    mavenBom 'io.spring.platform:platform-bom:+' // 2.0.1.RELEASE
    }
 }

dependencies {
  compile  'javax.jms:javax.jms-api:+' //2.0
  compile  'javax.mail:mail:+' //1.4.6
  compile  'javax.validation:validation-api' //1.0.0.GA
  compile  'org.springframework.security:spring-security-ldap' //4.0.1.RELEASE
  compile  'org.springframework.data:spring-data-jpa'  //1.9.1.RELEASE
  compile 'org.hibernate.javax.persistence:hibernate-jpa-2.0-api:+' //1.0.0.Final    
 }

build.gradle 用于app模块

apply plugin: 'java'
apply from: '../common.gradle'
dependencies {
compile project(':Core')
compile 'org.hibernate:hibernate-validator' //5.1.1.Final
compile 'net.sf.ehcache:ehcache'   //2.9.1
compile 'org.springframework:spring-jms' //4.2.3.RELEASE
 compile 'org.springframework:spring-oxm' //3.0.4.RELEASE }

Error message 片段:

FAILURE:构建因异常而失败 .

  • 出现了什么问题:无法解析配置':app:compile'的所有依赖项 .

找不到org.hibernate:hibernate-validator: . 在以下位置搜索:https://repo1.maven.org/maven2/org/hibernate/hibernate-validator//hibernate-validator-.pom https://repo1.maven.org/maven2/org/hibernate/hibernate -validator // hibernate-validator-.jar http://repo.grails.org/grails/repo/org/hibernate/hibernate-validator//hibernate-validator-.pom http://repo.grails.org/grails /repo/org/hibernate/hibernate-validator//hibernate-validator-.jar必需:Root:app:unspecified

Environment

D:\ personal> gradle -v


Gradle 2.9

Build time:2015-11-17 07:02:17 UTC Build number:none修订:b463d7980c40d44c4657dc80025275b84a29e31f

Groovy:2.4.4

Ant:2013年12月23日编译的Apache Ant(TM)版本1.9.3

JVM:1.8.0_20(Oracle Corporation 25.20-b23)

操作系统:Windows 7 6.1 amd64

1 回答

  • 1

    您应该将依赖关系管理插件添加到app模块 . 现在它是应用程序模块中的's only available in the core module, but you are trying to use it'功能 .
    将插件应用于每个模块可能是个好主意 . 如果需要,可以将其添加到root build.gradle:

    buildscript {
        repositories { mavenCentral() }
        dependencies { classpath "io.spring.gradle:dependency-management-plugin:0.5.4.RELEASE" }
    }
    
    allprojects {
        apply plugin: "io.spring.dependency-management"
    }
    

    回答评论:
    当工件不属于platform-bom时,工件需要显式版本 . 您可以声明自己的依赖项并在没有显式版本的情况下使用它们:

    dependencyManagement {
         dependencies {
              dependency 'org.springframework:spring-core:4.0.3.RELEASE'
              dependency group:'commons-logging', name:'commons-logging', version:'1.1.2'
         }
    }
    
    dependencies {
         compile 'org.springframework:spring-core'
    }
    

    来源:plugin documentation

相关问题