我正在使用gradle构建项目的Java应用程序。 gradle构建会创建一个模糊的可执行jar。
我在项目中使用过log4j库,我想使用gradle创建两个带有调试日志的jar,一个没有调试日志的jar。
build.gradle
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath "net.sf.proguard:proguard-gradle:6.1.1"
}
}
plugins {
id 'java'
id 'maven-publish'
}
repositories {
maven {
url = 'http://repo.maven.apache.org/maven2'
}
}
dependencies {
compile 'org.testng:testng:6.14.3'
compile 'io.appium:java-client:7.0.0'
compile 'org.apache.poi:poi:3.16'
compile 'net.sourceforge.tess4j:tess4j:4.3.0'
compile 'log4j:log4j:1.2.17'
testCompile 'junit:junit:4.11'
}
group = 'com.mobile'
version = '0.1'
description = 'AppiumTest'
sourceCompatibility = '1.8'
publishing {
publications {
maven(MavenPublication) {
from(components.java)
}
}
}
jar{
duplicatesStrategy = 'exclude'
from { configurations.compile.collect { zipTree(it) } }
manifest {
attributes 'Implementation-Title': 'Jar File with dependencies',
'Implementation-Version': version,
'Main-Class': 'com.mobile.MobileTest.App'
}
}
task proguardTask(type: proguard.gradle.ProGuardTask,dependsOn: jar) {
configuration file('proguard.pro')
injars 'build/libs/MobileTest-0.1.jar'
outjars 'build/libs/MobileTest-0.1-obfus.jar'
libraryjars "${System.getProperty('java.home')}/lib/rt.jar"
}
tasks.withType(JavaCompile) {
options.encoding = 'UTF-8'
}
test {
useTestNG()
}
任何帮助将不胜感激。