Skip to content

Compile plugins with -parameters to retain parameter names in spec - #28

Merged
bentsherman merged 2 commits into
masterfrom
compile-with-parameters
Oct 28, 2026
Merged

bentsherman merged 2 commits into
masterfrom
compile-with-parameters

Conversation

@bentsherman

Copy link
Copy Markdown
Member

Closes #27

Plugins were compiled without method parameter metadata, so generateSpec (via FunctionSpec, which uses Parameter.getName()) wrote arg0, arg1, … into spec.json, and the language server showed those names for plugin functions.

This enables -parameters for all JavaCompile tasks and groovyOptions.parameters for all GroovyCompile tasks.

Verified with a minimal plugin (one Groovy and one Java @Function) built against this checkout:

  • before: [{"name": "arg0", "type": "Path"}, {"name": "arg1", "type": "Path"}]
  • after: [{"name": "provenance", "type": "Path"}, {"name": "result", "type": "Path"}]

Added a unit test for the compile options; ./gradlew test passes.

@pditommaso pditommaso left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, the approach is right. One gap: Java sources compiled jointly with Groovy (i.e. .java files under src/main/groovy) still lose their parameter names.

Those files are compiled by compileGroovy, not compileJava. Gradle passes them to javac with GroovyCompile.options.compilerArgs; groovyOptions.parameters only affects the Groovy compiler and is never forwarded to javac.

I verified this with a small project (one .java and one .groovy class under src/main/groovy), checking the output with javap -v:

GroovyCompile config G.groovy J.java
groovyOptions.parameters = true only (this PR) alpha ✅ no MethodParameters ❌ → arg0, arg1
+ options.compilerArgs.add('-parameters') alpha ✅ provenance, result ✅

Suggested fix:

project.tasks.withType(GroovyCompile).configureEach { task ->
    task.groovyOptions.parameters = true
    // Java sources jointly compiled with Groovy
    task.options.compilerArgs.add('-parameters')
}

and in the test:

project.tasks.compileGroovy.options.compilerArgs.contains('-parameters')

Minor: worth a changelog note that plugins need to rebuild with the new gradle plugin version to get correct names in spec.json; already published plugins keep arg0.

@bentsherman

Copy link
Copy Markdown
Member Author

Good catch, thanks. I reproduced it: a Java @Function under src/main/groovy still got arg0/arg1 with only groovyOptions.parameters.

Applied your suggestion in acd384b: GroovyCompile now also passes -parameters to javac, and the test checks compileGroovy.options.compilerArgs. With that, the jointly compiled Java function gets sampleId/lane, and ./gradlew test passes.

I'll add the changelog note (plugins must rebuild with the new version to get real names in spec.json) in the release commit, since that's where changelog.txt gets updated.

@pditommaso pditommaso left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Verified end to end via includeBuild: Groovy, Java, and jointly compiled Java @Functions now get real parameter names in spec.json (previously arg0, arg1), and all Nextflow core plugins still build cleanly.

Nice to have: guard against adding -parameters twice when a plugin build already sets it (e.g. if (!args.contains('-parameters')) args.add('-parameters')). Harmless as is.

@bentsherman
bentsherman merged commit cedaf05 into master Oct 28, 2026
4 checks passed
@bentsherman
bentsherman deleted the compile-with-parameters branch October 28, 2026 20:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Compile plugins with -parameters, so spec.json has real parameter names

2 participants