jayware / gradle-osgi-ds

Easy to use gradle plugin to generate Declarative Services XML files
Apache License 2.0
2 stars 3 forks source link

Plugin fails to get the `compileJava` task when the apply() method is called #2

Closed renatoathaydes closed 7 years ago

renatoathaydes commented 7 years ago

This plugin causes the following error when applied to my project:

 Failed to apply plugin [id 'org.jayware.osgi-ds']
   > Task with path 'compileJava' not found in root project 'custom-java-command'.

That's because in the apply() method, this Plugin assumes the java plugin already added the compileJava task to the project, but that is not always the case as the order in which plugins are applied cannot be assumed by Gradle plugins.

The correct way to "use" a task from a different plugin is to use Gradle's callback mechanism, something like this (in Groovy):

project.tasks.withType( AbstractCompile ) { AbstractCompile compileTask ->
    task.inputs.files( compileTask )
    task.mustRunAfter( compileTask )
}
renatoathaydes commented 7 years ago

Notice that this will allow this plugin to support other languages in the JVM, including Kotlin, Scala, Ceylon and Groovy.

kKdH commented 7 years ago

Hello Renato, i apologize for the late feedback. I have changed the apply() operation as you suggested and released a new version (0.5.4) of the plugin.

Please let me know whether it solves your issue.