@@ -12,9 +12,22 @@ import org.gradle.api.tasks.*
12
12
import java.io.*
13
13
14
14
open 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
15
23
@InputDirectory
16
24
@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
18
31
19
32
@InputDirectory
20
33
@PathSensitive(PathSensitivity .RELATIVE )
@@ -26,10 +39,11 @@ open class ApiCompareCompareTask : DefaultTask() {
26
39
27
40
@TaskAction
28
41
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
+ }
33
47
34
48
val subject = project.name
35
49
val apiBuildDirFiles = mutableSetOf<RelativePath >()
@@ -55,8 +69,7 @@ open class ApiCompareCompareTask : DefaultTask() {
55
69
val expectedFile = expectedApiDeclaration.getFile(projectApiDir)
56
70
val actualFile = expectedApiDeclaration.getFile(apiBuildDir)
57
71
val diff = compareFiles(expectedFile, actualFile)
58
- if (diff != null )
59
- diffSet.add(diff)
72
+ if (diff != null ) diffSet.add(diff)
60
73
if (diffSet.isNotEmpty()) {
61
74
val diffText = diffSet.joinToString(" \n\n " )
62
75
error(" API check failed for project $subject .\n $diffText \n\n You can run :$subject :apiDump task to overwrite API declarations" )
0 commit comments