I have a @Configuration
class annotated with @EnableScheduling
and I want it to be disabled during the mvn clean install
command.
The problem is that it also triggers the start & stop goals, due to the Spring-Doc maven plugin, https://springdoc.org/#maven-plugin
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>${spring-boot-maven-plugin.version}</version>
<configuration>
<jvmArguments>-Dspring.application.admin.enabled=true</jvmArguments>
</configuration>
<executions>
<execution>
<goals>
<goal>start</goal>
<goal>stop</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.springdoc</groupId>
<artifactId>springdoc-openapi-maven-plugin</artifactId>
<version>1.4</version>
<executions>
<execution>
<id>integration-test</id>
<goals>
<goal>generate</goal>
</goals>
</execution>
</executions>
</plugin>
Is there a way to set some environment variable, e.g. SCHEDULING_ENABLED=false
, during the maven clean install
command in order to avoid the scheduling jobs at compile time ?
Update
I can't simply skip the springdoc generate loagoal because I have to download the OpenAPI yaml file.
I updated my configuration class as follows:
@Configuration
@ConditionalOnProperty(prefix = "scheduling", value = "enabled", havingValue = "true")
@EnableScheduling
public class SchedulingConfiguration {
@Value("${scheduling.enabled}")
private Boolean schedulingEnabled;
@PostConstruct
public void init(){
System.out.println("Scheduling enabled: " + this.schedulingEnabled);
}
}
and these are th two application.yml
:
src/main/resources/application.yml
scheduling:
enabled: true
src/test/resources/application.yml
scheduling:
enabled: false
However, during the mvn clean install command I alway get Scheduling enabled: true
on the console.
Is there something I am missing?
Update 2
I did upload a minimal project on GitHub https://github.com/MaurizioCasciano/Scheduling-Demo showing the problem.
My idea is that the following pom.xml snippet, required by Spring-Doc, simply starts the app as usual without any particular profile, e.g. test properties:
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>start</goal>
<goal>stop</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.springdoc</groupId>
<artifactId>springdoc-openapi-maven-plugin</artifactId>
<version>1.4</version>
<executions>
<execution>
<phase>integration-test</phase>
<goals>
<goal>generate</goal>
</goals>
</execution>
</executions>
<configuration>
<apiDocsUrl>http://localhost:8081/v3/api-docs.yaml</apiDocsUrl>
<outputFileName>API.yaml</outputFileName>
<outputDir>src/main/resources/api</outputDir>
</configuration>
</plugin>
</plugins>
</build>
Is it possible to specify here the properties to load or the Spring-Boot profile to activate?