我有基于Maven的spring-boot应用程序。
我想将h2数据库仅作为测试的依赖项,因此它具有以下内容:
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<scope>test</scope>
</dependency>
Run Code Online (Sandbox Code Playgroud)
那么我需要一个maven配置文件进行开发,需要将h2作为编译或运行时依赖项:
<profile>
<id>emb</id>
<activation>
<activeByDefault>false</activeByDefault>
</activation>
<dependencies>
<!-- Using embedded database in development -->
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<scope>compile</scope>
</dependency>
</dependencies>
</profile>
Run Code Online (Sandbox Code Playgroud)
但是由于仅使用测试范围,它在“无法加载驱动程序类:org.h2.Driver”上仍然失败。
当我从依赖关系中删除测试范围规范时,它可以工作,但这不是我想要的,因为我不想在生产中使用。
有可能如何基于配置文件重写依赖关系范围吗?