groovy / GMavenPlus

A rewrite of GMaven, a Maven plugin for Groovy
Other
285 stars 35 forks source link

The generateStubs goal ignores @BaseScript for Groovy scripts #209

Closed crizzis closed 2 years ago

crizzis commented 2 years ago

Base script class:

import java.util.function.Predicate

import static groovy.lang.Closure.DELEGATE_ONLY

abstract class TransformDsl extends Script {
    ...
}

@BaseScript - annotated Groovy script:

import groovy.transform.BaseScript

@BaseScript TransformDsl transformDsl

... // script body

Generated stub:

public class literals
  extends groovy.lang.Script {
;
public literals
() {}
public literals
(groovy.lang.Binding context) {
super ();
}
public static  void main(java.lang.String... args) { }
public  java.lang.Object run() { return (java.lang.Object)null;}
}

Tried both the annotated variable and annotated package syntax, same result

keeganwitt commented 2 years ago

I believe this is an issue in Groovy's stub generator. I don't think the stub generator looks handles the @BaseScript annotation. If you don't mind my asking, why do you need it in the stubs? This feature is typically used in Groovy scripts, which wouldn't be compiled (or shared with Java). But if this is something you need, we can open a Jira.

crizzis commented 2 years ago

I'm trying to create a custom groovy dsl, with (among other things) the class declaration stripped off. I reference the generated classes directly in my code (I'm calling Script.run() programmatically), so I do compile the files written using the dsl. I also need a base script class to provide the root methods exposed by the dsl. I found a workaround, though: I disabled stub generation for those particular scripts, then used the addStubSources goal to reference stubs from another location (which I created by hand). So this feature is now a nice-to-have for me.

crizzis commented 2 years ago

Opened a JIRA here: https://issues.apache.org/jira/browse/GROOVY-10584?filter=-2

Closing this ticket. Thanks for your help!

keeganwitt commented 2 years ago

Thanks for reporting this!