1、问题

最近从构建环境更新完jar后,Refresh Gradle Project时报错:xxx.jar cannot be read or is not a valid ZIP file

Archive for required library: 'D:/service/lib/core/nd-core-1.0.jar' in project 'nd-common' cannot be read or is not a valid ZIP file

The project cannot be built until build path errors are resolved

2、Gradle配置

  • build.gradle
apply from: '../config.gradle'

// Apply the java plugin to add support for Java
apply plugin: 'java'

def trd = ext.path.trd
def core = ext.path.core

// In this section you declare the dependencies for your production and test code
dependencies {

	compile fileTree(dir: trd, include: '*.jar')
	compile fileTree(dir: core, include:['nd-core-*.jar'], exclude:['stbk-*.jar'])

}
  • config.gradle
ext
{
	path=[
		trd:'D:/service/lib/trd',
		core:'D:/service/lib/core'
	]
}

3、原因

根据错误提示,找到’D:/service/lib/core/nd-core-1.0.jar’文件,使用解压软件打开或检测时都提示压缩文件已损坏。

4、解决方法

从svn上下载源码使用gradle build自己打包然后替换被损坏的文件即可或直接链接源码。总之,确实是jar包已损坏导致的,只要使用正常的文件即可解决。

注意:gradle文件中的路径也要保证是绝对有效的。