Skip to content

Simplify Gradle scripts that use AntlrKotlinTask #221

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jun 10, 2025

Conversation

lppedd
Copy link
Contributor

@lppedd lppedd commented Jun 8, 2025

No description provided.

```

6. Register the `build/generatedAntlr` directory as part of the common source set.
5. Use the `generateKotlinGrammarSource` task to provide an additional source directory
Copy link
Member

@ftomassetti ftomassetti Jun 9, 2025

Choose a reason for hiding this comment

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

How do we specify such source directory? Do we use a standard path or should it be expressly defined by the user?

Copy link
Contributor Author

@lppedd lppedd Jun 9, 2025

Choose a reason for hiding this comment

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

@ftomassetti I've recently learnt that Gradle is able to infer the directory path automatically thanks to the @OutputDirectory-annotated property in the custom task. So inputting the task instance to srcDir is all what's needed.

Copy link
Member

Choose a reason for hiding this comment

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

Ok, but the way in which it is phrased I interpreted to mean that when using the generateKotlinGrammarSource we will specify the source directory we want. While instead I think that what happens is that the generateKotlinGrammarSource target will generate Kotlin code for the lexer, parser, or combined grammars found under src/main/antlr and all the generated code will be produced in a certain directory (which is pre-defined in the gradle plugin and the user cannot pick). What the user needs to do is to instruct gradle to consider that directory where the code is generated as a source directory.

By the way, I wonder if we should do that automatically by default.

So instead of:

Use the generateKotlinGrammarSource task to provide an additional source directory to the commonMain source set. Gradle will then infer the task dependency automatically.

I would write:

Specify that the output directory of the `generateKotlinGrammarSource` task should be included as a source directory in the commonMain source set. In Gradle, you can do that by simply reference the task itself, and Gradle will automatically infer the associated output directory and include such directory in the source set.

What do you think?

Copy link
Contributor Author

@lppedd lppedd Jun 10, 2025

Choose a reason for hiding this comment

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

@ftomassetti makes sense to update that sentence in the readme. Your version sounds better, indeed.

Copy link
Member

Choose a reason for hiding this comment

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

Thank you, then I will merge it and then change the sentence

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Perfect, thanks!

Copy link
Member

@ftomassetti ftomassetti left a comment

Choose a reason for hiding this comment

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

It looks good to me, I have just a single comment on the README

@ftomassetti ftomassetti merged commit 67fa278 into Strumenta:master Jun 10, 2025
6 checks passed
@lppedd lppedd deleted the build/simplify-kts branch June 10, 2025 09:11
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.

2 participants