build-helper的add-test-sources功能的bug

简介:

  最新在项目中需要修改Maven创建的目录结构,需要添加一些source目录。熟悉maven的同学都知道,如果需要修改目录结构,可以通过修改pom.xml完成。具体如下:

 
  1. <build> 
  2.   <directory>${project.basedir}/target</directory> 
  3.   <outputDirectory>${project.build.directory}/classes</outputDirectory> 
  4.   <finalName>${project.artifactId}-${project.version}</finalName> 
  5.   <testOutputDirectory>${project.build.directory}/test-classes</testOutputDirectory> 
  6.   <sourceDirectory>${project.basedir}/src/main/java</sourceDirectory> 
  7.   <!-- TODO: MNG-3731 maven-plugin-tools-api < 2.4.4 expect this to be relative... --> 
  8.   <scriptSourceDirectory>src/main/scripts</scriptSourceDirectory> 
  9.   <testSourceDirectory>${project.basedir}/src/test/java</testSourceDirectory> 
  10.   <resources> 
  11.     <resource> 
  12.       <directory>${project.basedir}/src/main/resources</directory> 
  13.     </resource> 
  14.   </resources> 
  15.   <testResources> 
  16.     <testResource> 
  17.       <directory>${project.basedir}/src/test/resources</directory> 
  18.     </testResource> 
  19.   </testResources> 
  20. </build> 

  Maven能够按照标准化的方式来编译、打包等就是依赖于安装目录apache-maven-2.2.1\lib下的maven-2.2.1-uber.jar下面的org\apache\maven\project\pom-4.0.0.xml来完成的。那如果需要增加源代码包和测试源代码包该如何办呢? 使用build-helper来完成。

 build-helper是maven的plugin, 官网:http://mojo.codehaus.org/build-helper-maven-plugin/, 使用说明:http://mojo.codehaus.org/build-helper-maven-plugin/usage.html

 (1)增加源代码包

 
  1. <plugin> 
  2.                 <groupId>org.codehaus.mojo</groupId> 
  3.                 <artifactId>build-helper-maven-plugin</artifactId> 
  4.                 <version>1.5</version> 
  5.                 <executions> 
  6.                     <execution> 
  7.                         <id>add-source</id> 
  8.                         <phase>generate-sources</phase> 
  9.                         <goals> 
  10.                             <goal>add-source</goal> 
  11.                         </goals> 
  12.                         <configuration> 
  13.                             <sources> 
  14.                                 <source>src/junit/java</source> 
  15.                                 <source>src/junit/resources</source> 
  16.                             </sources> 
  17.                         </configuration> 
  18.                     </execution> 
  19.                 </executions> 
  20.             </plugin> 

(2)添加测试源代码包

 
  1. <plugin> 
  2.        <groupId>org.codehaus.mojo</groupId> 
  3.        <artifactId>build-helper-maven-plugin</artifactId> 
  4.        <version>1.5</version> 
  5.        <executions> 
  6.          <execution> 
  7.            <id>add-test-source</id> 
  8.            <phase>generate-test-sources</phase> 
  9.            <goals> 
  10.              <goal>add-test-source</goal> 
  11.            </goals> 
  12.            <configuration> 
  13.              <sources> 
  14.                <source>some directory</source> 
  15.                ... 
  16.              </sources> 
  17.            </configuration> 
  18.          </execution> 
  19.        </executions> 
  20.      </plugin> 

添加测试源代码包后,通过mvn eclipse:eclipse生成eclipse工程之后,却无法在eclipse的源代码build path中看到,而添加源代码包是可以的。查阅了官网的bug库,该bug至今处于open状态。参考:https://issues.sonatype.org/browse/MNGECLIPSE-2387

 

 本文转自 tianya23 51CTO博客,原文链接:http://blog.51cto.com/tianya23/578003,如需转载请自行联系原作者

相关文章
|
10月前
CMake Error: The source “xxx“ does not match the source “yyy“ used to generate cache. Re-run cmake
CMake Error: The source “xxx“ does not match the source “yyy“ used to generate cache. Re-run cmake
408 0
|
11天前
|
Python
IDA3.12版本的python,依旧报错IDAPython: error executing init.py.No module named ‘impRefer to the message win
IDA3.12版本的python,依旧报错IDAPython: error executing init.py.No module named ‘impRefer to the message win
|
6月前
|
数据可视化 Python
常见的bug---5、在安装superset时候报错,Command “python setup.py egg_info“ failed with error code 1
常见的bug---5、在安装superset时候报错,Command “python setup.py egg_info“ failed with error code 1
|
9月前
|
C++
下载node-gyp依赖包报错:gyp ERR! find VS msvs_version not set from command line or npm config
就是有一点需要注意,我这里安装vs的时候,可用里面没有vs社区版2017,只有2022,只能安装了2022
|
11月前
|
Java 测试技术 Maven
IntelliJ IDEA中执行@Test单元测试时报错Class not found: "..."Empty test suite
IntelliJ IDEA中执行@Test单元测试时报错Class not found: "..."Empty test suite
269 0
|
C++
编译JDK11:ERROR: Build failed for target ‘default (exploded-image)‘ in configuration ‘windows-x86_64
编译JDK11:ERROR: Build failed for target ‘default (exploded-image)‘ in configuration ‘windows-x86_64
208 0
|
开发工具 git
编译pluma:configure.ac:229: error: required file ‘pluma/mate-submodules/Makefile.in‘ not found
编译pluma:configure.ac:229: error: required file ‘pluma/mate-submodules/Makefile.in‘ not found
98 0
|
开发工具 git
Can‘t find third_party/gtest. Run git submodule update --init, or disable with CMake -DBUILD_TEST
Can‘t find third_party/gtest. Run git submodule update --init, or disable with CMake -DBUILD_TEST
101 0
Perhaps you should add the directory containing libpcre.pc to the PKG_CONFIG_PATH
Perhaps you should add the directory containing libpcre.pc to the PKG_CONFIG_PATH
101 0
|
Linux 网络虚拟化
ROS安装遇到 sudo rosdep init 与rosdep update出现error loading sources list
ROS安装遇到 sudo rosdep init 与rosdep update出现error loading sources list
227 0
ROS安装遇到 sudo rosdep init 与rosdep update出现error loading sources list