cloudflightio / springboot-testresources

Spring Boot Test Resources powered by TestContainers and Micronaut
Apache License 2.0
21 stars 2 forks source link

dependencies.dependency.version for testcontainers is missing #16

Open shelajev opened 1 year ago

shelajev commented 1 year ago

I'm trying springboot-testresources on a Spring Boot Petclinic app, and I think I followed the instructions properly, but when i try to build it, or run the individual test from my IDE (PetClinicIntegrationTests), then it fails with the following error:

> Task :internalStartTestResourcesService
Errors occurred while build effective model from /Users/shelajev/.gradle/caches/modules-2/files-2.1/io.cloudflight.testresources.springboot/springboot-testresources-jdbc-postgres/0.2.0/133bd2af448e4f364498b889a8d5e6847e3881a9/springboot-testresources-jdbc-postgres-0.2.0.pom:
        'dependencies.dependency.version' for org.testcontainers:postgresql:jar is missing. in io.cloudflight.testresources.springboot:springboot-testresources-jdbc-postgres:0.2.0
Errors occurred while build effective model from /Users/shelajev/.gradle/caches/modules-2/files-2.1/io.cloudflight.testresources.springboot/springboot-testresources-jdbc/0.2.0/fe2291622201c55906afb3fc811c7dc5450fcc3a/springboot-testresources-jdbc-0.2.0.pom:
        'dependencies.dependency.version' for org.testcontainers:jdbc:jar is missing. in io.cloudflight.testresources.springboot:springboot-testresources-jdbc:0.2.0

Do you know what can I try to resolve? I added Testcontainers BOM to explicitly provide the versions, but it doesn't seem to help.

The project if you want to try it is here: Github repo

klu2 commented 1 year ago

Hey, sorry for the late reply, I missed your ticket.

Your issue seems to be related with the Spring Dependency Plugin, see https://github.com/spring-gradle-plugins/dependency-management-plugin/issues/319, and https://github.com/r2dbc/r2dbc-bom/issues/44

Unfortunately I couldn't fix it using this plugin, but I found a probable even better approach without the plugin at all. If you change your build.gradle to the following:

plugins {
  id 'org.springframework.boot' version '3.0.1'
  id 'java'
  id("io.micronaut.test-resources") version "3.6.7"
}

apply plugin: 'java'

group = 'org.springframework.samples'
version = '3.0.0'
sourceCompatibility = '17'

repositories {
  mavenCentral()
}

ext.webjarsFontawesomeVersion = "4.7.0"
ext.webjarsBootstrapVersion = "5.1.3"
ext.springBootVersion = "3.0.1"

dependencies {
    implementation platform("org.springframework.boot:spring-boot-dependencies:${springBootVersion}")
    developmentOnly platform("org.springframework.boot:spring-boot-dependencies:${springBootVersion}")

    implementation 'org.springframework.boot:spring-boot-starter-cache'
    implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
    implementation 'org.springframework.boot:spring-boot-starter-thymeleaf'
    implementation 'org.springframework.boot:spring-boot-starter-web'
    implementation 'org.springframework.boot:spring-boot-starter-validation'
    implementation 'javax.cache:cache-api'
    implementation 'jakarta.xml.bind:jakarta.xml.bind-api'
    runtimeOnly 'org.springframework.boot:spring-boot-starter-actuator'
    runtimeOnly "org.webjars.npm:bootstrap:${webjarsBootstrapVersion}"
    runtimeOnly "org.webjars.npm:font-awesome:${webjarsFontawesomeVersion}"
    runtimeOnly 'com.github.ben-manes.caffeine:caffeine'
    runtimeOnly 'com.mysql:mysql-connector-j'
    runtimeOnly 'org.postgresql:postgresql'
    developmentOnly 'org.springframework.boot:spring-boot-devtools'
    testImplementation 'org.springframework.boot:spring-boot-starter-test'

    testRuntimeOnly("io.cloudflight.testresources.springboot:springboot-testresources-client:0.2.0")
    testResourcesImplementation ("io.cloudflight.testresources.springboot:springboot-testresources-jdbc-postgres:0.2.0")
    testImplementation "org.testcontainers:postgresql"
}

tasks.named('test') {
  useJUnitPlatform()
}

Then you're participating in Gradle's native platform functionality and dependency resolution works fine.