2016-01-28 16 views
5

Tôi có xấp xỉ thiết lập sau:mùa xuân khởi động gradle Plugin lực lượng Mockito phiên bản

test-utils/build.gradle:

buildscript { 
    repositories { 
     jcenter() 
    } 
    dependencies { 
     classpath 'org.springframework.boot:spring-boot-gradle-plugin:1.3.1.RELEASE' 
    } 
} 

apply plugin: 'java' 
apply plugin: 'spring-boot' 

dependencies { 
    compile ('org.springframework.boot:spring-boot-starter-test') { 
     exclude group: 'org.mockito' 
     exclude group: 'org.hamcrest' 
    } 
    compile 'org.mockito:mockito-core:2.0.41-beta' 
    compile 'org.assertj:assertj-core:3.3.0' 
} 

main/build.gradle:

buildscript { 
    repositories { 
     jcenter() 
    } 
    dependencies { 
     classpath 'org.springframework.boot:spring-boot-gradle-plugin:1.3.1.RELEASE' 
    } 
} 

apply plugin: 'java' 
apply plugin: 'spring-boot' 

dependencies { 
    testCompile project(':test-utils') 
} 

Nhưng đối với một số lý do có vẻ như mùa xuân plugin khởi động buộc phiên bản mockito quay lại 1.x:

# ./gradlew :main:dependencies --configuration=testCompile 

testCompile - Compile classpath for source set 'test'. 
+--- project :test-utils 
    +--- org.springframework.boot:spring-boot-starter-test: -> 1.3.1.RELEASE 
    | +--- junit:junit:4.12 
    | +--- org.springframework:spring-core:4.2.4.RELEASE 
    | \--- org.springframework:spring-test:4.2.4.RELEASE 
    |   \--- org.springframework:spring-core:4.2.4.RELEASE 
    +--- org.mockito:mockito-core:2.0.41-beta -> 1.10.19 
    | +--- org.hamcrest:hamcrest-core:1.1 -> 1.3 
    | \--- org.objenesis:objenesis:2.1 
    \--- org.assertj:assertj-core:3.3.0 

Nếu tôi mất plugin khởi động mùa xuân ra khỏi phương trình, mọi thứ hoạt động như mong đợi:

# ./gradlew :main:dependencies --configuration=testCompile 

testCompile - Compile classpath for source set 'test'. 
+--- project :test-utils 
    +--- org.springframework:spring-core:4.2.4.RELEASE (*) 
    +--- org.springframework:spring-test:4.2.4.RELEASE 
    | \--- org.springframework:spring-core:4.2.4.RELEASE (*) 
    +--- junit:junit:4.12 
    +--- org.mockito:mockito-core:2.0.41-beta 
    | +--- net.bytebuddy:byte-buddy:1.0.2 
    | \--- org.objenesis:objenesis:2.1 
    \--- org.assertj:assertj-core:3.3.0 

boot Plugin mùa xuân làm chính xác là gì, và làm thế nào tôi có thể nói nó không đến?

Trả lời

4

Dự án main của bạn có plugin Spring Boot được áp dụng cho nó, do đó, nó sử dụng quản lý phụ thuộc của Spring Boot. Điều đó có nghĩa là theo mặc định, nó sẽ sử dụng phiên bản Mockito ưa thích của Spring Boot, bất kể phiên bản được liệt kê trong test-utils.

described in the documentation, bạn có thể ghi đè phiên bản phụ thuộc mà Khởi động mùa xuân quản lý bằng cách đặt thuộc tính có liên quan. Đối với Mockito, thuộc tính đó là mockito.version. Thêm nội dung sau vào dự án main của bạn:

ext['mockito.version'] = '2.0.41-beta' 
+0

Tôi chỉ biết câu trả lời sẽ bao gồm lần truy cập "như được mô tả trong tài liệu" ...: - /. Tôi đã tìm kiếm rất nhiều từ "spring boot gradle" nhưng bây giờ tôi biết câu trả lời nằm trong "Build", tôi nhận thấy rằng [this] (https://github.com/spring-gradle-plugins/dependency-management-plugin/ # overriding-versions-in-a-bom) chỉ bằng một cú nhấp chuột từ [here] (https://docs.spring.io/spring-boot/docs/current/reference/html/build-tool-plugins-gradle- plugin.html). Thở dài. –

Các vấn đề liên quan