chore: keep docker compose dependency with test scope.

This commit is contained in:
Josep Maria Formentí Serra 2024-05-18 14:16:50 +02:00
parent 68dfdddd4d
commit 5aedb47310
4 changed files with 14 additions and 25 deletions

15
pom.xml
View file

@ -68,10 +68,6 @@
<artifactId>spring-boot-starter-test</artifactId> <artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope> <scope>test</scope>
</dependency> </dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-docker-compose</artifactId>
</dependency>
<!-- Databases - Uses H2 by default --> <!-- Databases - Uses H2 by default -->
<dependency> <dependency>
@ -122,6 +118,11 @@
<artifactId>spring-boot-testcontainers</artifactId> <artifactId>spring-boot-testcontainers</artifactId>
<scope>test</scope> <scope>test</scope>
</dependency> </dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-docker-compose</artifactId>
<scope>test</scope>
</dependency>
<dependency> <dependency>
<groupId>org.testcontainers</groupId> <groupId>org.testcontainers</groupId>
<artifactId>junit-jupiter</artifactId> <artifactId>junit-jupiter</artifactId>
@ -219,7 +220,7 @@
<artifactId>spring-boot-maven-plugin</artifactId> <artifactId>spring-boot-maven-plugin</artifactId>
<executions> <executions>
<execution> <execution>
<!-- Spring Boot Actuator displays build-related information <!-- Spring Boot Actuator displays build-related information
if a META-INF/build-info.properties file is present --> if a META-INF/build-info.properties file is present -->
<goals> <goals>
<goal>build-info</goal> <goal>build-info</goal>
@ -377,7 +378,7 @@
<build> <build>
<pluginManagement> <pluginManagement>
<plugins> <plugins>
<!-- This plugin's configuration is used to store Eclipse m2e settings <!-- This plugin's configuration is used to store Eclipse m2e settings
only. It has no influence on the Maven build itself. --> only. It has no influence on the Maven build itself. -->
<plugin> <plugin>
<groupId>org.eclipse.m2e</groupId> <groupId>org.eclipse.m2e</groupId>
@ -435,4 +436,4 @@
</profile> </profile>
</profiles> </profiles>
</project> </project>

View file

@ -52,13 +52,13 @@ A similar setup is provided for MySQL and PostgreSQL if a persistent database co
You only need to pass the Spring Boot profile at the time of running the application: You only need to pass the Spring Boot profile at the time of running the application:
```bash ```bash
./mvnw spring-boot:run -Dspring-boot.run.profiles=mysql ./mvnw spring-boot:test-run -Dstart-class=org.springframework.samples.petclinic.MysqlTestApplication
``` ```
or or
```bash ```bash
./mvnw spring-boot:run -Dspring-boot.run.profiles=postgres ./mvnw spring-boot:test-run -Dstart-class=org.springframework.samples.petclinic.PostgresIntegrationTests
``` ```
## Test Applications ## Test Applications

View file

@ -16,12 +16,8 @@
package org.springframework.samples.petclinic; package org.springframework.samples.petclinic;
import org.springframework.boot.SpringApplication; import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.testcontainers.service.connection.ServiceConnection;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Profile;
import org.testcontainers.containers.MySQLContainer;
/** /**
* PetClinic Spring Boot Application. * PetClinic Spring Boot Application.
@ -32,15 +28,10 @@ import org.testcontainers.containers.MySQLContainer;
@Configuration @Configuration
public class MysqlTestApplication { public class MysqlTestApplication {
@ServiceConnection
@Profile("mysql")
@Bean
static MySQLContainer<?> container() {
return new MySQLContainer<>("mysql:8.2");
}
public static void main(String[] args) { public static void main(String[] args) {
SpringApplication.run(PetClinicApplication.class, "--spring.profiles.active=mysql"); new SpringApplicationBuilder(PetClinicApplication.class) //
.profiles("mysql") //
.run(args);
} }
} }

View file

@ -70,9 +70,6 @@ public class PostgresIntegrationTests {
public static void main(String[] args) { public static void main(String[] args) {
new SpringApplicationBuilder(PetClinicApplication.class) // new SpringApplicationBuilder(PetClinicApplication.class) //
.profiles("postgres") // .profiles("postgres") //
.properties( //
"spring.docker.compose.profiles.active=postgres" //
) //
.listeners(new PropertiesLogger()) // .listeners(new PropertiesLogger()) //
.run(args); .run(args);
} }