License info is more reliably added to archive tasks

master
Robinson 2023-01-17 00:52:49 +01:00
parent 9757fa15ee
commit a364276bde
No known key found for this signature in database
GPG Key ID: 8E7DB78588BD6F5C
1 changed files with 11 additions and 4 deletions

View File

@ -17,8 +17,10 @@
package dorkbox.license
import License
import org.gradle.api.Action
import org.gradle.api.DefaultTask
import org.gradle.api.GradleException
import org.gradle.api.Task
import org.gradle.api.publish.PublishingExtension
import org.gradle.api.publish.maven.MavenPublication
import org.gradle.api.tasks.Input
@ -100,13 +102,18 @@ internal open class LicenseInjector @Inject constructor(@Internal val extension:
}
// the task will only build files that it needs to (and will only run once)
project.tasks.forEach {
if (it is AbstractArchiveTask) {
project.tasks.withType(AbstractArchiveTask::class.java, object: Action<Task> {
override fun execute(task: Task) {
task as AbstractArchiveTask
// make sure that the license info is always built before the task
task.dependsOn(extension)
// don't include the license file from the root directory (which happens by default).
// make sure that our license files are included in task resources (when building a jar, for example)
it.from(extension.jarOutput)
task.from(extension.jarOutput)
}
}
})
}
// true if there was any work done. checks while it goes as well