gav*_*koa 8 java ant build-process build maven
我想在Maven中检查属性文件中的身份验证数据是否由开发人员在应用程序测试期间提供,如果调用集成测试生命周期.
作为状态惯例,将认证数据提交给源树是不好的.在用户名和密码等设置中描述的标准maven方法不应与pom.xml一起分发.
但我不喜欢这种方法(我想要每个checkout设置,而不是每个dev-host !!)并且想要在VCS(SVN/GIT/HG)中提供src/text/resources/auth.properties.example作为示例,想要在Maven中检查是否存在src/text/resources/auth.properties的代码,这是每个开发人员拥有的(或者每个项目结账!!)但是只有在调用了集成测试阶段时(或者在集成之后的任何其他阶段)测试阶段).如果执行任何先前阶段(如编译或测试) - 必须禁用此检查.
Maven 验证阶段旨在检查构建一致性(请参阅引入生命周期).但是没有任何阶段的检查!所以我使用预集成测试阶段.
我写了工作代码:
<?xml version="1.0" encoding="utf-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.mycompany.app</groupId>
<artifactId>my-app</artifactId>
<packaging>jar</packaging>
<version>1.0</version>
<name>my-app</name>
<profiles>
<profile>
<id>existent.properties</id>
<activation>
<file>
<missing>auth.properties</missing>
</file>
</activation>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.6</version>
<executions>
<execution>
<phase>pre-integration-test</phase>
<goals>
<goal>run</goal>
</goals>
<configuration>
<target>
<echo>In order to run integration-text life-cycle:</echo>
<echo> 1) Rename 'auth.properties.example' into 'auth.properties'.</echo>
<echo> 2) Fill 'auth.properties' with your own authentification data.</echo>
<fail message="Can't find 'auth.properties'."/>
</target>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
</profiles>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.6</version>
<executions>
<execution>
<id>test</id>
<phase>test</phase>
<goals>
<goal>run</goal>
</goals>
<configuration>
<target>
<echo>JUnit tests!</echo>
</target>
</configuration>
</execution>
<execution>
<id>integration-test</id>
<phase>integration-test</phase>
<goals>
<goal>run</goal>
</goals>
<configuration>
<target>
<echo>Selenium tests!</echo>
</target>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
但作为GNU Make guru,我不喜欢上面的代码.我对吗?使用Maven是错误的吗?
你的方法很好(如果有点过度设计恕我直言 - 我只是把这种东西放在自述文件/项目维基中;当尝试读取它时,如果没有文件,构建应该会失败)
您可能还想使用 Enforcer 目标而不是 antrun:http://maven.apache.org/enforcer/enforcer-rules/requireFilesExist.html