在我们的maven模块中,我们有多个资源文件夹
src/main/prod/sql
和src/main/dev/sql
。在prod中,我们有生产脚本,其中有大量数据插入。当激活profile local时,我们需要用dev / sql中的文件覆盖prod / sql目录中的一些文件。
这是配置
<profiles>
<profile>
<id>local</id>
<activation>
<activeByDefault>false</activeByDefault>
</activation>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<version>3.1.0</version>
<executions>
<execution>
<id>copy-files</id>
<phase>process-resources</phase>
<goals>
<goal>copy-resources</goal>
</goals>
<configuration>
<overwrite>true</overwrite>
<outputDirectory>${basedir}/target/classes/sql</outputDirectory>
<resources>
<resource>
<directory>src/main/dev/</directory>
<filtering>true</filtering>
</resource>
</resources>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
当我们使用干净安装构建模块时,始终存在来自目标目录中的prod / sql的脚本。你能告诉我我做错了什么吗?谢谢。
你用mvn clean install
建造吗?
如果是这种情况,<activeByDefault>true</activeByDefault>
参数不允许默认运行local
配置文件,您应该使用mvn clean install -Plocal
构建,在构建期间加载local
配置文件
或者,修改pom.xml
以始终使用local
配置文件:
<profiles>
<profile>
<id>local</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
...