【发布时间】:2018-12-10 15:50:24
【问题描述】:
我有基于 maven 的 spring-boot 应用程序。
我希望将 h2 数据库作为仅用于测试的依赖项,因此我将其设置如下:
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<scope>test</scope>
</dependency>
然后我需要一个用于开发的 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>
但它仍然在“无法加载驱动程序类:org.h2.Driver”上失败,因为它仅使用测试范围。
当我从依赖项中删除测试范围规范时,它可以工作,但这不是我想要的,因为我不想在生产中使用。
是否有可能如何根据配置文件重写依赖范围?
【问题讨论】:
标签: java maven spring-boot h2 dependency-management