|
1 | 1 | package com.vanniktech.code.quality.tools |
2 | 2 |
|
3 | | -import com.android.build.gradle.BaseExtension |
| 3 | +import com.android.build.api.dsl.ApplicationExtension |
| 4 | +import com.android.build.api.dsl.LibraryExtension |
| 5 | +import com.android.build.api.dsl.Lint |
| 6 | +import com.android.build.api.dsl.TestExtension |
4 | 7 | import com.android.build.gradle.LintPlugin |
5 | | -import com.android.build.gradle.internal.dsl.LintOptions |
6 | 8 | import de.aaschmid.gradle.plugins.cpd.Cpd |
7 | 9 | import de.aaschmid.gradle.plugins.cpd.CpdExtension |
8 | 10 | import de.aaschmid.gradle.plugins.cpd.CpdPlugin |
@@ -143,54 +145,56 @@ fun Project.addCheckstyle(rootProject: Project, extension: CodeQualityToolsPlugi |
143 | 145 | fun Project.addLint(extension: CodeQualityToolsPluginExtension): Boolean { |
144 | 146 | val isNotIgnored = !shouldIgnore(extension) |
145 | 147 | val isEnabled = extension.lint.enabled |
146 | | - val isAndroidProject = isAndroidProject() |
147 | 148 | val isJavaProject = isJavaProject() |
148 | 149 |
|
149 | 150 | if (isNotIgnored && isEnabled) { |
150 | | - val lintOptions = if (isAndroidProject) { |
151 | | - extensions.getByType(BaseExtension::class.java).lintOptions |
152 | | - } else if (isJavaProject && hasLintPlugin()) { |
153 | | - plugins.apply(LintPlugin::class.java) |
154 | | - extensions.getByType(LintOptions::class.java) |
155 | | - } else { |
156 | | - null |
| 151 | + val lintOptions = when { |
| 152 | + plugins.hasPlugin("com.android.application") -> extensions.getByType(ApplicationExtension::class.java).lint |
| 153 | + plugins.hasPlugin("com.android.library") -> extensions.getByType(LibraryExtension::class.java).lint |
| 154 | + plugins.hasPlugin("com.android.test") -> extensions.getByType(TestExtension::class.java).lint |
| 155 | + isJavaProject && hasLintPlugin() -> { |
| 156 | + plugins.apply(LintPlugin::class.java) |
| 157 | + extensions.getByType(Lint::class.java) |
| 158 | + } |
| 159 | + else -> { |
| 160 | + null |
| 161 | + } |
157 | 162 | } |
158 | 163 |
|
159 | 164 | if (lintOptions != null) { |
160 | | - lintOptions.isWarningsAsErrors = extension.lint.warningsAsErrors ?: extension.failEarly |
161 | | - lintOptions.isAbortOnError = extension.lint.abortOnError ?: extension.failEarly |
| 165 | + lintOptions.warningsAsErrors = extension.lint.warningsAsErrors ?: extension.failEarly |
| 166 | + lintOptions.abortOnError = extension.lint.abortOnError ?: extension.failEarly |
162 | 167 |
|
163 | 168 | extension.lint.checkAllWarnings?.let { |
164 | | - lintOptions.isCheckAllWarnings = it |
| 169 | + lintOptions.checkAllWarnings = it |
165 | 170 | } |
166 | 171 |
|
167 | 172 | extension.lint.absolutePaths?.let { |
168 | | - lintOptions.isAbsolutePaths = it |
| 173 | + lintOptions.absolutePaths = it |
169 | 174 | } |
170 | 175 |
|
171 | 176 | extension.lint.baselineFileName?.let { |
172 | | - lintOptions.baselineFile = file(it) |
| 177 | + lintOptions.baseline = file(it) |
173 | 178 | } |
174 | 179 |
|
175 | 180 | extension.lint.lintConfig?.let { |
176 | 181 | lintOptions.lintConfig = it |
177 | 182 | } |
178 | 183 |
|
179 | 184 | extension.lint.checkReleaseBuilds?.let { |
180 | | - lintOptions.isCheckReleaseBuilds = it |
| 185 | + lintOptions.checkReleaseBuilds = it |
181 | 186 | } |
182 | 187 |
|
183 | 188 | extension.lint.checkTestSources?.let { |
184 | | - lintOptions.isCheckTestSources = it |
| 189 | + lintOptions.checkTestSources = it |
185 | 190 | } |
186 | 191 |
|
187 | 192 | extension.lint.checkDependencies?.let { |
188 | | - lintOptions.isCheckDependencies = it |
| 193 | + lintOptions.checkDependencies = it |
189 | 194 | } |
190 | 195 |
|
191 | 196 | extension.lint.textReport?.let { |
192 | 197 | lintOptions.textReport = it |
193 | | - lintOptions.textOutput(extension.lint.textOutput) |
194 | 198 | } |
195 | 199 |
|
196 | 200 | tasks.named(CHECK_TASK_NAME).configure { it.dependsOn("lint") } |
@@ -231,7 +235,6 @@ fun Project.addKtlint(rootProject: Project, extension: CodeQualityToolsPluginExt |
231 | 235 | } |
232 | 236 |
|
233 | 237 | configuration.isCanBeConsumed = false |
234 | | - configuration.isVisible = false |
235 | 238 |
|
236 | 239 | configuration.defaultDependencies { |
237 | 240 | it.add(dependencies.create("com.pinterest.ktlint:ktlint-cli:${extension.ktlint.toolVersion}")) |
|
0 commit comments