使用maven打包后,在META-INF目录下会生成pom.properties文件(当然可以使其不生成)。这个文件包含了包的Id信息,此外它最开始有两行注释,看起来是这样的
#Generated by Maven #Sat Jun 25 09:40:37 CST 2016
第一行 是固定的,第二行是打包时候的时间戳。
第二行的存在有一个严重的问题,就是我们完全不修改代码,然后两次打包由于时间戳不一样,导致生成的两个包不一样。如果你不在乎可能觉得没有什么,但是对于大型项目,代码没变包却不同导致不能进行增量部署。
这个代码的出现是由于java.util.Properties类的store(Writer writer, String comments)方法中有一行
bw.write("#" + new Date().toString());
这个问题在困扰大家的同时,也困扰着Maven的开发者。与之相关的有两个issue:
maven人员郁闷的说
Oracle's implementation of store() does write the stupid new Date().toString()
由于大家需求强烈,目前该特性据说已被修正。
在今年5月21号提交的代码中,时间这一行注释被移除了:移除方法是把生成后的文件对行迭代,看到是注释就删除。
Stupid hack: write the properties to a StringWriter, iterate with a BufferedReader and drop all comments, finall write real content to the target file.
我们看一下中心库中的版本和时间:
3.0.x版本最晚是4月份提交的,所以它不包含这个改动。3.1.x最早是6月份提交的,现在已经有两个小版本了,但是引用次数还是0.
我们对比一下3.0和3.1中的代码。首先是3.0.2中的:
75 private void createPropertiesFile( MavenSession session, Properties properties, File outputFile, 76 boolean forceCreation ) 77 throws IOException 78 { 79 File outputDir = outputFile.getParentFile(); 80 if ( outputDir != null && !outputDir.isDirectory() && !outputDir.mkdirs() ) 81 { 82 throw new IOException( "Failed to create directory: " + outputDir ); 83 } 84 if ( !forceCreation && sameContents( properties, outputFile ) ) 85 { 86 return; 87 } 88 OutputStream os = new FileOutputStream( outputFile ); 89 try 90 { 91 String createdBy = CREATED_BY_MAVEN; 92 if ( session != null ) // can be null due to API backwards compatibility 93 { 94 String mavenVersion = session.getSystemProperties().getProperty( "maven.version" ); 95 if ( mavenVersion != null ) 96 { 97 createdBy += " " + mavenVersion; 98 } 99 } 100 101 properties.store( os, createdBy ); 102 os.close(); // stream is flushed but not closed by Properties.store() 103 os = null; 104 } 105 finally 106 { 107 IOUtil.close( os ); 108 } 109 }
下面是3.1.1的(左边是在文件内的行号):
77 private void createPropertiesFile( MavenSession session, Properties properties, File outputFile, 78 boolean forceCreation ) 79 throws IOException 80 { 81 File outputDir = outputFile.getParentFile(); 82 if ( outputDir != null && !outputDir.isDirectory() && !outputDir.mkdirs() ) 83 { 84 throw new IOException( "Failed to create directory: " + outputDir ); 85 } 86 if ( !forceCreation && sameContents( properties, outputFile ) ) 87 { 88 return; 89 } 90 PrintWriter pw = new PrintWriter( outputFile, "ISO-8859-1" ); 91 try 92 { 93 String createdBy = CREATED_BY_MAVEN; 94 if ( session != null ) // can be null due to API backwards compatibility 95 { 96 String mavenVersion = session.getSystemProperties().getProperty( "maven.version" ); 97 if ( mavenVersion != null ) 98 { 99 createdBy += " " + mavenVersion; 100 } 101 } 102 103 StringWriter sw = new StringWriter(); 104 properties.store( sw, null ); 105 106 BufferedReader r = new BufferedReader( new StringReader( sw.toString() ) ); 107 108 pw.println( "#" + createdBy ); 109 String line; 110 while ( ( line = r.readLine() ) != null ) 111 { 112 if ( !line.startsWith( "#" ) ) 113 { 114 pw.println( line ); 115 } 116 } 117 118 r.close(); 119 r = null; 120 sw.close(); 121 sw = null; 122 pw.close(); 123 pw = null; 124 } 125 finally 126 { 127 IOUtil.close( pw ); 128 } 129 }
这里主要是对注释的处理,正文内容的处理在方法public void createPomProperties()中。
下面版本比上面多了一个流程,就是临时变量sw写入后,再逐行读出来,不是注释就写入pw中(迭代前已经把maven信息写好了)。这样就把时间删掉了。
相关推荐
从包含org.eclipse.jdt.core.prefs文件的maven-compiler-plugin的依赖项中读取,或者从configuration / compilerArguments / properties中读取。 允许配置Maven依赖关系和JRE类路径容器的外部注释的路径。 路径是取...
赠送Maven依赖信息文件:eigenbase-properties-1.1.5.pom; 包含翻译后的API文档:eigenbase-properties-1.1.5-javadoc-API文档-中文(简体)版.zip; Maven坐标:net.hydromatic:eigenbase-properties:1.1.5; 标签:...
Maven依赖:【***.jar Maven依赖信息(可用于项目pom.xml).txt】 Gradle依赖:【***.jar Gradle依赖信息(可用于项目build.gradle).txt】 源代码下载地址:【***-sources.jar下载地址(官方地址+国内镜像地址).txt】...
强大的过滤功能来检查和重新分类发现的问题 通过注释存在过滤的能力 Maven 插件自动在检查中包含依赖项 其他特性: 能够根据 semver 规则判断更改的严重程度(请参阅 ) 根据 semver 规则自动更新 pom.xml 或 ...
请注意,无论何时更改数据库类型,都需要更新data-access.properties文件,并且不需要对pom.xml中的mysql-connector-java工件进行注释。 您可以使用docker启动MySql数据库: docker run -e MYSQL_ROOT_PASSWORD=...
在idea中执行package打包时,打包2次,是因为pom.xml文件中下边插件引起的,把这个注释掉 <groupId>org.springframework.boot <artifactId>spring-boot-maven-plugin 一个tomcat中部署多个类似项目,将报错 Unable...
安装提取zip文件夹并更新到maven项目,然后使用maven命令从cmd运行pom.xml或运行配置文件。 要求-JDK8或更高版本以及maven 3.6.0或更高版本。 * testScript用Java编写,具有清晰的语法和带有免费代码的注释。 *定位...
类中的每个程序包都包含一些JAVA原则以及可用于学习目的的注释。 安装 安装IDE(推荐:IntelliJ IDEA) 安装Java JDK(从以下下载: : ) 将此项目的git存储库克隆到本地驱动器(或将其下载为zip存档) 打开文件...
如果不想执行此行为,请在 pom.xml 文件中注释相应部分; 在这种情况下,您也不需要下载 execute-maven-plugin。模板默认模板在src/main/resources/defaultTemplate.html 。 您可以将其用作模板来定义自定义报告...
长子生成器 虚拟机平台地位OpenJDK LTS Linux OpenJDK当前Linux OpenJDK当前视窗建筑要构建此... 有关详细信息,请参见POM中的“ properties部分。 primogenitor POM严重偏重于广泛的静态检查以及逐字节可。 通过将项目
要引入mybatis-generator:在pom.xml-构建-插件-插件中引入mybatis -generator-maven-plugin立即 mybatis-generator的配置文件是generatorConfig.xml,里面有完整的注释,这里就不多讲了 datasource.properties中...
评论删除 CommentRemover是Java:trade_mark:7及更高版本的源代码注释删除库... 添加依赖项后,请运行mvn clean install命令并确保已完成maven清理和安装过程。 < id>jitpack.io < url>https://jitpack.io</ url
介绍 该存储库应该用作使用测试自动化项目的模板。 它包含纯Java和Cucumber方法。 它是基于最佳实践库的测试自动化模板,并添加了一些缺失的功能,这些功能... 设置并取消注释属性neodymium.webDriver.chrome.pathTo
4.项目Maven打包问题。 打包的时候,不同版本的 Eclipse 还有IDEA 会有打包打不进去Mapper.xml 文件,这个时候要加如下代码(群里同学提供的)。 <directory>src/main/java **/*.properties **/*.xml ...