1

I generated new micronaut project with cli: mn create-app --lang java check-test-resources --features data,flyway,postgres,test-resources,jooq

This is my build.gradle:

plugins {
    id("com.github.johnrengelman.shadow") version "7.1.2"
    id("io.micronaut.application") version "3.7.0"
    id("io.micronaut.test-resources") version "3.7.0"
}

version = "0.1"
group = "check.test.resources"

repositories {
    mavenCentral()
}

dependencies {
    annotationProcessor("io.micronaut:micronaut-http-validation")
    implementation("io.micronaut:micronaut-http-client")
    implementation("io.micronaut:micronaut-jackson-databind")
    implementation("io.micronaut.flyway:micronaut-flyway")
    implementation("io.micronaut.sql:micronaut-jdbc-hikari")
    implementation("io.micronaut.sql:micronaut-jooq")
    implementation("jakarta.annotation:jakarta.annotation-api")
    runtimeOnly("ch.qos.logback:logback-classic")
    runtimeOnly("org.postgresql:postgresql")
    implementation("io.micronaut:micronaut-validation")

}


application {
    mainClass.set("check.test.resources.Application")
}
java {
    sourceCompatibility = JavaVersion.toVersion("17")
    targetCompatibility = JavaVersion.toVersion("17")
}

graalvmNative.toolchainDetection = false
micronaut {
    runtime("netty")
    testRuntime("junit5")
    processing {
        incremental(true)
        annotations("check.test.resources.*")
    }
}




This is my application.yml:

micronaut:
  application:
    name: checkTestResources
datasources:
  default:
    driver-class-name: org.postgresql.Driver
    db-type: postgres
flyway:
  datasources:
    default:
      enabled: true
netty:
  default:
    allocator:
      max-order: 3

test-resources:
  containers:
    postgres:
      image-name: postgres:14.6

And from what I understand from docs when I run ./gradlew test my postgresql should be created and used if needed, but unfortunately I got this message:

Bean definition [javax.sql.DataSource] could not be loaded: Error instantiating bean of type  [javax.sql.DataSource]

Message: Error configuring data source 'default'. No URL specified
Path Taken: DataSource.dataSource(DatasourceConfiguration datasourceConfiguration) --> DataSource.dataSource([DatasourceConfiguration datasourceConfiguration])
io.micronaut.context.exceptions.BeanInstantiationException: Bean definition [javax.sql.DataSource] could not be loaded: Error instantiating bean of type  [javax.sql.DataSource]

What am I doing wrong? I would like to use testcontainers via test-resources in my micronaut project.

1 Answers1

3

Your CLI command is wrong.

mn create-app --lang java check-test-resources --features **data**,flyway,postgres,test-resources,jooq

data isn't a valid option. Should be data-jdbc, data-jpa, data-r2dbc, data-mongo or etc.

Recommend using Micronaut Launch to select the features you want then click on Generate Project -> Commands

With this configuration the CLI command would be:

mn create-app --build=gradle --jdk=17 --lang=java --test=junit --features=jooq,postgres,flyway,test-resources,data-jdbc com.example.demo

ShingJo
  • 614
  • 1
  • 7