Maven build 跟eclipse build有何不同
来源:互联网 发布:国际顶级域名注册 编辑:程序博客网 时间:2024/04/29 08:02
Maven build的时候,推荐使用clean install -DskipTests,如下面这个命令,因为这个命令会把test包下面的java代码还有配置文件都编译,但是不会运行测试类进行测试。
但是如果是下面这种方式,则压根就不会编译test包下面的java源文件以及配置文件,如果要进行手动测试,那么不推荐使用这种方式。
标准的Maven项目包层次结构:
-Project
--src/main/java
--src/main/resources
--src/test/java(如果是用-DskipTests,那么也会编译这些测试类,但是如果勾选Skip tests则不会)
--src/test/resources(如果是用-DskipTests,那么也会编译这些资源文件,但是如果勾选Skip tests则不会)
有时候我们的项目测试的时候可能依赖其他项目的配置文件,那么我们就需要使用maven build的方式把他们加进来。如下面的示例
这个示例在我们build 代码的时候会执行下面操作,最后一个是把某一个专门存放配置文件的项目(build出来是zip文件)build出来的zip文件解压缩,放到generated-sources 还有generated-test-sources中。generated-test-sources这个是运行测试类会用到的配置文件。
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<version>2.7</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.3</version>
<executions>
<execution>
<id>XXXXX-build</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
<configuration>
<descriptors>
<descriptor>src/main/assembly/XXXXX.xml</descriptor>
</descriptors>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<id>unpack-XXXXXX-resources</id>
<goals>
<goal>unpack-dependencies</goal>
</goals>
<phase>generate-resources</phase>
<configuration>
<outputDirectory>${project.build.directory}/generated-resources</outputDirectory>
<includeArtifacIds>ArtifacId</includeArtifacIds>
<includeGroupIds>GroupId</includeGroupIds>
<excludeTransitive>true</excludeTransitive>
<includeTypes>zip</includeTypes>
<includeClassifiers>resources</includeClassifiers>
<includeScopes>provided</includeScopes>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
另外,如果我对于不同的场有很多种不同的配置文件,那么我可以用profile去配置不同场的不同配置文件
在src/main/resources下面创建不同场的不同文件夹
那么在pom文件中如何配置呢
<modelVersion>4.0.0</modelVersion><groupId>XXX</groupId>
<artifactId>XXX</artifactId>
<name>XXX</name>
<packaging>pom</packaging>
<version>${XXX}</version>
<profiles>
<profile>
<id>A</id>
<properties>
<package.id>A</package.id>
<package.environment>A</package.environment>
</properties>
</profile>
<profile>
<id>B</id>
<properties>
<package.id>B</package.id>
<package.environment>B</package.environment>
</properties>
</profile>
<profile>
<id>test_config</id>
<properties>
<package.id>test_config</package.id>
<package.environment>test_config</package.environment>
</properties>
</profile>生成的zip文件后面会加上你的profile的名字,比如XXX-5.0.0-02-SNAPSHOT-test_config.zip
下面是另外一个pom配置模板,用于测试的时候,从其他配置文件项目拷贝配置文件过来
<profiles><profile>
<id>test_config</id> <!-- Test profile -->
<build>
<testResources>
<testResource>
<directory>src/test/resources</directory>
</testResource>
<testResource>
<directory>${project.build.directory}/generated-test-resources</directory>
</testResource>
</testResources>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<id>unpack-test-config</id>
<goals>
<goal>unpack-dependencies</goal>
</goals>
<phase>generate-test-resources</phase>
<configuration>
<outputDirectory>${project.build.directory}/generated-test-resources</outputDirectory>
<includeArtifacIds>ArtifacId</includeArtifacIds>
<includeGroupIds>GroupId</includeGroupIds>
<excludeTransitive>true</excludeTransitive>
<includeTypes>zip</includeTypes>
<includeClassifiers>test_config</includeClassifiers>
<includeScopes>test</includeScopes>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
<dependencies>这个依赖只属于这个profile
<dependency>
<groupId>groupId</groupId>
<artifactId>artifactId</artifactId>
<classifier>test_config</classifier>
<type>zip</type>
<scope>test</scope>
</dependency>
</dependencies>
</profile>
</profiles>
下面是关于Skip tests 还有-DskipTests的测试
使用-DskipTests的build 结果,generated-test-resources跟test-classes也会被编译生成
勾选Skip tests的运行结果,generated-test-resources跟test-classes不会被编译生成
- Maven build 跟eclipse build有何不同
- eclipse maven build 配置
- Maven&Eclipse build java project.
- Maven: Setting maven build goals in eclipse
- eclipse maven 项目 maven build 无反应
- maven build
- Eclipse Maven install build 无任何作用
- maven项目在eclipse中build
- Eclipse中配置Maven build打包
- Eclipse中执行Maven的build命令
- eclipse下,maven Build项目出错
- eclipse maven build 命令执行启动项目
- Eclipse Maven Build命令执行无效解决方法
- eclipse 中Maven项目 的maven install 、build 、clean
- <为知更新>eclipse生成的apk和系统编译产生的apk有何不同
- JavaBean与EJB有何不同
- 管理与领导有何不同
- 管理与领导有何不同
- Android高级Renderscript---Andvanced Renderscript(四)
- SQL: rank over
- 错误:Invalid value around character 0.
- LeetCode-383. Ransom Note
- 结合上面的图片压缩方法
- Maven build 跟eclipse build有何不同
- 事件机制-Spring 源码系列(4)
- 国内外知名IT科技博客(强烈推荐)
- 关于“IIS版本号可以被识别”
- pivot实现列转行
- 网络-OSI分层模型与TCP/ IP分层模型以及相关协议
- codeblocks 汉化教程
- 使用VideoView+MediaController实现视频播放器
- sql server 请求失败或服务未及时响应