I found in a hard way that Groovy is not very backwards compatible with java and therefore kotlin. You can surely call both java and kotlin classes from Groovy (in case of kotlin it is a bit disappointing since Groovy and Kotlin have many similar features, but they are not interoperable), but you can’t easily call Groovy from Java and Kotlin. In theory, you can, but Groovy dynamic features always get in a way.
First recommendation: Do not try to do it. Implement all your logic in Kotlin/Java and Groovy only as a fine user interface layer.
Second recommendation. If you definitely need it, use a groovy @CompileStatic
.
In your case, you can try to create a groovy wrapper class extending NpmTask
and make it call some Kotlin code (calls from Groovy to Kotlin work just fine).