build.gradle 4.0 KB
Newer Older
S
Skylot 已提交
1
plugins {
S
Skylot 已提交
2
	id 'com.github.ben-manes.versions' version '0.38.0'
3
	id "com.diffplug.spotless" version "5.12.4"
S
Skylot 已提交
4 5
}

6
ext.jadxVersion = System.getenv('JADX_VERSION') ?: "dev"
S
Skylot 已提交
7
version = jadxVersion
8
println("jadx version: ${jadxVersion}")
S
Skylot 已提交
9

10
allprojects {
11
	apply plugin: 'java'
12
	apply plugin: 'checkstyle'
13 14 15

	version = jadxVersion

16 17 18
	sourceCompatibility = JavaVersion.VERSION_1_8
	targetCompatibility = JavaVersion.VERSION_1_8

19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
	tasks.withType(JavaCompile) {
		if (!"$it".contains(':jadx-samples:')) {
			options.compilerArgs << '-Xlint' << '-Xlint:unchecked' << '-Xlint:deprecation'
		}
	}

	compileJava {
		options.encoding = "UTF-8"
	}

	jar {
		manifest {
			mainAttributes('jadx-version': jadxVersion)
		}
	}

	dependencies {
36
		implementation 'org.slf4j:slf4j-api:1.7.30'
S
Skylot 已提交
37
		compileOnly 'org.jetbrains:annotations:20.1.0'
38

39 40
		testImplementation 'ch.qos.logback:logback-classic:1.2.3'
		testImplementation 'org.hamcrest:hamcrest-library:2.2'
41
		testImplementation 'org.mockito:mockito-core:3.9.0'
S
Skylot 已提交
42
		testImplementation 'org.assertj:assertj-core:3.19.0'
43

S
Skylot 已提交
44 45
		testImplementation 'org.junit.jupiter:junit-jupiter-api:5.7.1'
		testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.7.1'
46

47
		testImplementation 'org.eclipse.jdt.core.compiler:ecj:4.6.1'
S
Skylot 已提交
48
		testCompileOnly 'org.jetbrains:annotations:20.1.0'
49 50 51 52 53 54 55 56 57 58 59 60
	}

	test {
		useJUnitPlatform()
	}

	repositories {
		mavenLocal()
		mavenCentral()
		google()
	}

61 62 63 64
	checkstyleMain {
		// exclude all sources in samples module
		exclude '**/samples/**'
	}
65 66
}

67 68 69 70 71 72
spotless {
	java {
		target fileTree(rootDir).matching {
			include 'jadx-cli/src/**/java/**/*.java'
			include 'jadx-core/src/**/java/**/*.java'
			include 'jadx-gui/src/**/java/**/*.java'
73
			include 'jadx-plugins/**/java/**/*.java'
74 75 76 77
		}

		importOrderFile 'config/code-formatter/eclipse.importorder'
		eclipse().configFile 'config/code-formatter/eclipse.xml'
78 79 80 81 82 83
		if (JavaVersion.current() < JavaVersion.VERSION_16) {
			removeUnusedImports()
		} else {
			// google-format broken on java 16 (https://github.com/diffplug/spotless/issues/834)
			println('Warning! Unused imports remove is disabled for Java 16')
		}
84

85
		lineEndings(com.diffplug.spotless.LineEnding.UNIX)
86 87 88 89 90 91
		encoding("UTF-8")
		trimTrailingWhitespace()
		endWithNewline()
	}
	format 'misc', {
		target '**/*.gradle', '**/*.md', '**/*.xml', '**/.gitignore', '**/.properties'
92
		targetExclude ".gradle/**", ".idea/**", "*/build/**"
93

94
		lineEndings(com.diffplug.spotless.LineEnding.UNIX)
95 96 97 98
		encoding("UTF-8")
		trimTrailingWhitespace()
		endWithNewline()
	}
S
Skylot 已提交
99 100
}

101 102 103 104 105 106 107 108 109 110
dependencyUpdates {
	resolutionStrategy {
		componentSelection { rules ->
			rules.all { ComponentSelection selection ->
				boolean rejected = ['alpha', 'beta', 'rc', 'cr', 'm', 'atlassian'].any { qualifier ->
					selection.candidate.version ==~ /(?i).*[.-]${qualifier}[.\d-]*/
				}
				if (rejected) {
					selection.reject('Release candidate')
				}
111 112 113
			}
		}
	}
S
Skylot 已提交
114 115
}

116 117 118 119
task copyArtifacts(type: Copy) {
	from tasks.getByPath(":jadx-cli:installDist")
	from tasks.getByPath(":jadx-gui:installDist")
	into layout.buildDirectory.dir("jadx")
120
	duplicatesStrategy = DuplicatesStrategy.EXCLUDE
S
Skylot 已提交
121 122
}

123 124
task pack(type: Zip) {
	from copyArtifacts
125
	archiveFileName = "jadx-${jadxVersion}.zip"
126
	destinationDirectory = layout.buildDirectory
S
Skylot 已提交
127 128
}

129
task copyExe(type: Copy) {
130 131
	group 'jadx'
	description = 'Copy exe to build dir'
132 133 134
	mustRunAfter pack // not needed, but gradle throws warning because of same output dir

	from tasks.getByPath('jadx-gui:createExe')
135
	include '*.exe'
136
	into layout.buildDirectory
137
	duplicatesStrategy = DuplicatesStrategy.EXCLUDE
S
Skylot 已提交
138 139
}

140
task dist {
141 142
	group 'jadx'
	description = 'Build jadx distribution zip'
143 144 145 146 147 148 149 150 151

	dependsOn(pack)
	if (JavaVersion.current() < JavaVersion.VERSION_16) {
		dependsOn('copyExe')
	} else {
		// shadow jar plugin broken on java 16 (https://github.com/johnrengelman/shadow/issues/658)
		tasks.getByPath(':jadx-gui:shadowJar').enabled = false
		println('Warning! Build of jadx-gui.exe disabled for Java 16')
	}
S
Skylot 已提交
152 153
}

S
Skylot 已提交
154
task samples(dependsOn: 'jadx-samples:samples') {
155
	group 'jadx'
S
Skylot 已提交
156 157
}

S
Skylot 已提交
158
task cleanBuildDir(type: Delete) {
159 160
	group 'jadx'
	delete buildDir
S
Skylot 已提交
161 162
}

163
test.dependsOn(samples)
S
Skylot 已提交
164 165

clean.dependsOn(cleanBuildDir)