[英]Gradle: Neither path nor baseDir may be null or empty string
我試圖在我的Gradle腳本中使用ProGuard來每次構建時對我的代碼進行模糊處理,但是我遇到了以下錯誤:
FAILURE: Build failed with an exception.
* What went wrong:
Neither path nor baseDir may be null or empty string. path='null' basedir='/Users/hassansyyid/Workspace/Random/Launcher/launcher'
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
BUILD FAILED
Total time: 1.888 secs
這是我的build.gradle:
import proguard.gradle.ProGuardTask
apply plugin: 'com.github.johnrengelman.shadow'
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'net.sf.proguard:proguard-gradle:5.3.1'
}
}
jar {
manifest {
attributes("Main-Class": "com.skcraft.launcher.Launcher")
}
}
dependencies {
compile 'org.projectlombok:lombok:1.12.2'
compile 'com.fasterxml.jackson.core:jackson-databind:2.3.0'
compile 'commons-lang:commons-lang:2.6'
compile 'commons-io:commons-io:1.2'
compile 'com.google.guava:guava:15.0'
compile 'com.beust:jcommander:1.32'
compile 'com.miglayout:miglayout:3.7.4'
compile 'com.google.code.findbugs:jsr305:3.0.0'
}
processResources {
filesMatching('**/*.properties') {
filter {
it.replace('${project.version}', project.version)
}
}
}
task obfuscate(type: proguard.gradle.ProGuardTask) {
configuration 'proguard.txt'
injars "${buildDir}/libs/launcher-${version}.jar"
outjars "${buildDir}/libs/launcher-${version}-obf.jar"
libraryjars configurations.compile.find { it.name.startsWith("lombok") }
libraryjars configurations.compile.find { it.name.startsWith("jackson-databind") }
libraryjars configurations.compile.find { it.name.startsWith("jackson-core") }
libraryjars configurations.compile.find { it.name.startsWith("jackson-annotation") }
libraryjars configurations.compile.find { it.name.startsWith("crypto") }
libraryjars configurations.compile.find { it.name.startsWith("guava") }
libraryjars configurations.compile.find { it.name.startsWith("jcommander") }
libraryjars configurations.compile.find { it.name.startsWith("miglayout") }
libraryjars configurations.compile.find { it.name.startsWith("jsr305") }
libraryjars configurations.compile.find { it.name.startsWith("commons-io") }
libraryjars configurations.compile.find { it.name.startsWith("commons-lang") }
}
shadowJar {
dependencies {
exclude(dependency('org.projectlombok:lombok'))
}
}
build.dependsOn(shadowJar)
build.dependsOn(obfuscate)
我發現的關於該問題的唯一信息是它與obfuscate
任務有關。 我通過注釋build.dependsOn(obfuscate)
證實了這一點,並且構建成功了。
我查找了錯誤,但無法找到任何有用的信息。 另外,我正在運行最新的Gradle構建Gradle 3.1
。
我的proguard.txt:
# Include java runtime classes
-libraryjars <java.home>/lib/rt.jar
# Output a source map file
-printmapping proguard.map
# Keep filenames and line numbers
-keepattributes SourceFile, LineNumberTable
# Disable certain proguard optimizations which remove stackframes (same as Android defaults)
-optimizations !method/inlining/*
-keep public class * {
public protected *;
}
-keepclassmembernames class * {
java.lang.Class class$(java.lang.String);
java.lang.Class class$(java.lang.String, boolean);
}
-keepclasseswithmembernames class * {
native <methods>;
}
-keepclassmembers enum * {
public static **[] values();
public static ** valueOf(java.lang.String);
}
-keepclassmembers class * implements java.io.Serializable {
static final long serialVersionUID;
private static final java.io.ObjectStreamField[] serialPersistentFields;
private void writeObject(java.io.ObjectOutputStream);
private void readObject(java.io.ObjectInputStream);
java.lang.Object writeReplace();
java.lang.Object readResolve();
}
在此先感謝您的幫助!
問題似乎是您在ProGuard任務中聲明庫jar的方式。 根據ProGuard主頁上的文檔,需要為libraryjars
設置指定文件集合。
類路徑被指定為Gradle文件集合,這意味着可以將它們指定為簡單字符串,文件(Object)等。
我更新了您的gradle文件,並且能夠成功運行構建:
import proguard.gradle.ProGuardTask
apply plugin: 'com.github.johnrengelman.shadow'
apply plugin: 'java'
buildscript {
repositories {
mavenCentral()
jcenter()
}
dependencies {
classpath group: 'net.sf.proguard', name: 'proguard-gradle', version: '5.3.1'
classpath group: 'com.github.jengelman.gradle.plugins', name: 'shadow', version: '1.2.4'
}
}
repositories {
mavenCentral()
jcenter()
}
jar {
manifest { attributes("Main-Class": "com.skcraft.launcher.Launcher") }
}
dependencies {
compile 'org.projectlombok:lombok:1.12.2'
compile 'com.fasterxml.jackson.core:jackson-databind:2.3.0'
compile 'commons-lang:commons-lang:2.6'
compile 'commons-io:commons-io:1.2'
compile 'com.google.guava:guava:15.0'
compile 'com.beust:jcommander:1.32'
compile 'com.miglayout:miglayout:3.7.4'
compile 'com.google.code.findbugs:jsr305:3.0.0'
}
processResources {
filesMatching('**/*.properties') {
filter {
it.replace('${project.version}', project.version)
}
}
}
task obfuscate(type: proguard.gradle.ProGuardTask) {
configuration 'proguard.txt'
injars jar
outjars "${buildDir}/libs/launcher-${version}-obf.jar"
libraryjars files(configurations.compile.collect())
}
shadowJar {
dependencies {
exclude(dependency('org.projectlombok:lombok'))
}
}
build.dependsOn(shadowJar)
build.dependsOn(obfuscate)
task wrapper(type: Wrapper) { gradleVersion = "3.1" }
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.