@@ -12,9 +12,22 @@ import org.gradle.api.tasks.*
1212import java.io.*
1313
1414open class ApiCompareCompareTask : DefaultTask () {
15+
16+ /*
17+ * Nullability and optionality is a workaround for
18+ * https://github.com/gradle/gradle/issues/2016
19+ *
20+ * Unfortunately, there is no way to skip validation apart from setting 'null'
21+ */
22+ @Optional
1523 @InputDirectory
1624 @PathSensitive(PathSensitivity .RELATIVE )
17- lateinit var projectApiDir: File
25+ var projectApiDir: File ? = null
26+
27+ // Used for diagnostic error message when projectApiDir doesn't exist
28+ @Input
29+ @Optional
30+ var nonExistingProjectApiDir: String? = null
1831
1932 @InputDirectory
2033 @PathSensitive(PathSensitivity .RELATIVE )
@@ -26,10 +39,11 @@ open class ApiCompareCompareTask : DefaultTask() {
2639
2740 @TaskAction
2841 fun verify () {
29- if (! projectApiDir.exists())
30- error(" Expected folder with API declarations '$projectApiDir ' does not exist" )
31- if (! apiBuildDir.exists())
32- error(" Folder with built API declarations '$apiBuildDir ' does not exist" )
42+ val projectApiDir = projectApiDir
43+ if (projectApiDir == null ) {
44+ error(" Expected folder with API declarations '$nonExistingProjectApiDir ' does not exist.\n " +
45+ " Please ensure that ':apiDump' was executed in order to get API dump to compare the build against" )
46+ }
3347
3448 val subject = project.name
3549 val apiBuildDirFiles = mutableSetOf<RelativePath >()
@@ -55,8 +69,7 @@ open class ApiCompareCompareTask : DefaultTask() {
5569 val expectedFile = expectedApiDeclaration.getFile(projectApiDir)
5670 val actualFile = expectedApiDeclaration.getFile(apiBuildDir)
5771 val diff = compareFiles(expectedFile, actualFile)
58- if (diff != null )
59- diffSet.add(diff)
72+ if (diff != null ) diffSet.add(diff)
6073 if (diffSet.isNotEmpty()) {
6174 val diffText = diffSet.joinToString(" \n\n " )
6275 error(" API check failed for project $subject .\n $diffText \n\n You can run :$subject :apiDump task to overwrite API declarations" )
0 commit comments