我为不同的数据库提供了不同的maven配置文件和spring配置文件:mysql,postgresql。设置maven配置文件会添加相应的依赖项。设置弹簧轮廓会在运行时添加相应的弹簧属性。我想维护一个代码库并将两个不同的工件部署到我的存储库。
我想生成以下广告:${project.artifactId}-${target.database}-${project.version}
。
我尝试过使用分类器,但似乎无法为它们配置部署插件。好像你必须从命令行覆盖属性。使用此方法,生成的文件名将为:${project.artifactId}-${project.version}-${target.database}
(假设分类器以${target.database}
命名)。
这是否可以在pom中配置并发出标准maven命令只覆盖配置文件?
如果没有,最好的方法是什么?
总之,POM定义了每个环境配置文件:dev,int,uat和pro;和每个数据库配置文件(与以前的配置文件正交):mysql,postgresql。这里重要的配置文件是数据库配置文件。
<?xml version="1.0" encoding="UTF-8"?>
http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0
<groupId>com.byteflair</groupId>
<artifactId>oauth2-server</artifactId>
<version>0.1.0-RC1</version>
<packaging>jar</packaging>
<properties>
<start-class>com.byteflair.oauth.server.Oauth2ServerApp</start-class>
<java.version>1.8</java.version>
<spring-security.version>4.1.3.RELEASE</spring-security.version>
<sonar.version>2.7.1</sonar.version>
<spock.version>1.1-groovy-2.4-rc-2</spock.version>
<keystore.path>${project.build.directory}/keystore.jks</keystore.path>
<unit.skip>false</unit.skip>
<int.skip>false</int.skip>
<docker.skip>false</docker.skip>
</properties>
<profiles>
<profile>
<id>mysql</id>
<activation>
<property>
<name>spring.profiles.active</name>
<value>mysql</value>
</property>
</activation>
<properties>
<classifier>mysql</classifier>
</properties>
<build>
<plugins>
<plugin>
<groupId>io.fabric8</groupId>
<artifactId>docker-maven-plugin</artifactId>
<version>0.15.16</version>
<configuration>
<images>
<image>
<!--docker run --name mensosdb -p 27017:27017 -d mongo:3.0.8-->
<alias>oauthdb</alias>
<name>mysql:5.5</name>
<run>
<env>
<MYSQL_ROOT_PASSWORD>password</MYSQL_ROOT_PASSWORD>
<MYSQL_USER>oauth_server</MYSQL_USER>
<MYSQL_PASSWORD>password</MYSQL_PASSWORD>
<MYSQL_DATABASE>oauth_db</MYSQL_DATABASE>
</env>
<ports>
<port>3306:3306</port>
</ports>
<wait>
<log>mysqld: ready for connections.</log>
<time>20000</time>
</wait>
</run>
</image>
</images>
<skip>${docker.skip}</skip>
</configuration>
<executions>
<execution>
<id>start-containers</id>
<phase>pre-integration-test</phase>
<goals>
<goal>build</goal>
<goal>start</goal>
</goals>
</execution>
<execution>
<id>stop-containers</id>
<phase>post-integration-test</phase>
<goals>
<goal>stop</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.36</version>
</dependency>
</dependencies>
</profile>
<profile>
<id>postgresql</id>
<activation>
<property>
<name>spring.profiles.active</name>
<value>postgresql</value>
</property>
</activation>
<properties>
<classifier>postgresql</classifier>
</properties>
<build>
<plugins>
<plugin>
<groupId>io.fabric8</groupId>
<artifactId>docker-maven-plugin</artifactId>
<version>0.15.16</version>
<configuration>
<images>
<image>
<!--docker run --name mensosdb -p 27017:27017 -d mongo:3.0.8-->
<alias>oauthdb</alias>
<name>postgres:9.5</name>
<run>
<env>
<POSTGRES_USER>oauth_server</POSTGRES_USER>
<POSTGRES_PASSWORD>password</POSTGRES_PASSWORD>
<POSTGRES_DB>oauth_db</POSTGRES_DB>
</env>
<ports>
<port>5432:5432</port>
</ports>
<wait>
<log>database system is ready to accept connections</log>
<time>20000</time>
</wait>
</run>
</image>
</images>
<skip>${docker.skip}</skip>
</configuration>
<executions>
<execution>
<id>start-containers</id>
<phase>pre-integration-test</phase>
<goals>
<goal>build</goal>
<goal>start</goal>
</goals>
</execution>
<execution>
<id>stop-containers</id>
<phase>post-integration-test</phase>
<goals>
<goal>stop</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<version>9.4.1211</version>
</dependency>
</dependencies>
</profile>
<profile>
<id>dev</id>
<activation>
<property>
<name>spring.profiles.active</name>
<value>dev</value>
</property>
</activation>
<properties>
<unit.skip>false</unit.skip>
<int.skip>false</int.skip>
<docker.skip>false</docker.skip>
</properties>
</profile>
<profile>
<id>int</id>
<activation>
<property>
<name>spring.profiles.active</name>
<value>int</value>
</property>
</activation>
<properties>
<unit.skip>false</unit.skip>
<int.skip>false</int.skip>
<docker.skip>true</docker.skip>
</properties>
</profile>
<profile>
<id>uat</id>
<activation>
<property>
<name>spring.profiles.active</name>
<value>uat</value>
</property>
</activation>
<properties>
<unit.skip>false</unit.skip>
<int.skip>false</int.skip>
<docker.skip>true</docker.skip>
</properties>
</profile>
<profile>
<id>pro</id>
<activation>
<property>
<name>spring.profiles.active</name>
<value>pro</value>
</property>
</activation>
<properties>
<unit.skip>false</unit.skip>
<int.skip>false</int.skip>
<docker.skip>true</docker.skip>
</properties>
</profile>
</profiles>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.4.0.RELEASE</version>
</parent>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>keytool-maven-plugin</artifactId>
<version>1.5</version>
<executions>
<execution>
<goals>
<goal>generateKeyPair</goal>
</goals>
<phase>generate-resources</phase>
</execution>
</executions>
<configuration>
<keystore>${keystore.path}</keystore>
<dname>OU=Development, O=Byteflair, L=Madrid S=Madrid, C=Spain</dname>
<keyalg>rsa</keyalg>
<storepass>password</storepass>
<keypass>password</keypass>
<alias>dev_oauth_jwt_key</alias>
<skipIfExist>true</skipIfExist>
</configuration>
</plugin>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.projectlombok</groupId>
<artifactId>lombok-maven-plugin</artifactId>
<version>1.16.6.1</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<compilerVersion>1.8</compilerVersion>
<source>1.8</source>
<target>1.8</target>
<encoding>UTF8</encoding>
</configuration>
</plugin>
<plugin>
<!-- The gmavenplus plugin is used to compile Groovy code. To learn more about this plugin,
visit https://github.com/groovy/GMavenPlus/wiki -->
<groupId>org.codehaus.gmavenplus</groupId>
<artifactId>gmavenplus-plugin</artifactId>
<version>1.4</version>
<executions>
<execution>
<goals>
<goal>compile</goal>
<goal>testCompile</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.17</version>
<configuration>
<systemProperties>
<user.timezone>UTC</user.timezone>
</systemProperties>
<includes>
<include>**/*Test.java</include>
<include>**/*Spec.java</include>
</includes>
<skipTests>${unit.skip}</skipTests>
</configuration>
<executions>
<execution>
<goals>
<goal>test</goal>
<goal>test</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<version>2.17</version>
<configuration>
<skipTests>${int.skip}</skipTests>
<systemProperties>
<user.timezone>UTC</user.timezone>
</systemProperties>
<includes>
<include>**/*IT.java</include>
</includes>
</configuration>
<executions>
<execution>
<goals>
<goal>integration-test</goal>
<goal>verify</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.7.2.201409121644</version>
<executions>
<execution>
<id>default-prepare-agent</id>
<goals>
<goal>prepare-agent</goal>
</goals>
</execution>
<execution>
<id>default-report</id>
<phase>prepare-package</phase>
<goals>
<goal>report</goal>
</goals>
</execution>
<execution>
<id>default-prepare-agent-integration</id>
<goals>
<goal>prepare-agent-integration</goal>
</goals>
</execution>
<execution>
<id>default-report-integration</id>
<goals>
<goal>report-integration</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>sonar-maven-plugin</artifactId>
<version>${sonar.version}</version>
</plugin>
<plugin>
<artifactId>maven-jar-plugin</artifactId>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>jar</goal>
</goals>
<configuration>
<classifier>${classifier}</classifier>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-deploy-plugin</artifactId>
<executions>
<execution>
<phase>deploy</phase>
<goals>
<goal>deploy</goal>
</goals>
<configuration>
<classifier>${classifier}</classifier>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
<distributionManagement>
<repository>
<id>byteflair</id>
<name>Releases</name>
<url>https://nexus.byteflair.com/repository/maven-releases</url>
</repository>
<snapshotRepository>
<id>byteflair</id>
<name>Snapshot</name>
<url>https://nexus.byteflair.com/repository/maven-snapshots</url>
</snapshotRepository>
</distributionManagement>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.security.oauth</groupId>
<artifactId>spring-security-oauth2</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-jwt</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-freemarker</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-rest</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.plugin</groupId>
<artifactId>spring-plugin-core</artifactId>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.16.6</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.jayway.jsonpath</groupId>
<artifactId>json-path</artifactId>
<version>2.0.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>br.com.six2six</groupId>
<artifactId>fixture-factory</artifactId>
<version>3.0.0</version>
<exclusions>
<exclusion>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>io.rest-assured</groupId>
<artifactId>rest-assured</artifactId>
<version>3.0.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.rest-assured</groupId>
<artifactId>json-path</artifactId>
<version>3.0.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<!-- Mandatory dependencies for using Spock -->
<dependency>
<groupId>org.spockframework</groupId>
<artifactId>spock-core</artifactId>
<version>${spock.version}</version>
<scope>test</scope>
</dependency>
<!-- Optional dependencies for using Spock -->
<dependency>
<groupId>org.spockframework</groupId>
<artifactId>spock-spring</artifactId>
<version>${spock.version}</version>
<scope>test</scope>
</dependency>
<dependency> <!-- use a specific Groovy version rather than the one specified by spock-core -->
<groupId>org.codehaus.groovy</groupId>
<artifactId>groovy-all</artifactId>
<version>2.4.1</version>
</dependency>
<dependency>
<groupId>cglib</groupId>
<artifactId>cglib-nodep</artifactId>
<version>RELEASE</version>
</dependency>
</dependencies>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-releasetrain</artifactId>
<version>Hopper-SR2</version>
<type>pom</type>
<scope>import</scope>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-bom</artifactId>
<version>${spring-security.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>