Skip to content
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

Pass javacArguments to Kapt #387

Merged
merged 1 commit into from
May 26, 2024

Conversation

GavinRay97
Copy link
Contributor

Passes javacArguments option through to Kapt.
This is required for code which uses things like --enable-preview or --add-opens

(Closes: #385)

Kapt requires a Map<String, String> for it's javac arguments, so convert it from a List<String>

See the function working here:

val args = listOf(
    "-verbose",
    "-cp", "path/to/classes",
    "-J-Xmx512m",
    "-g:none",
    "-source", "1.8",
    "--add-opens", "java.base/java.util=ALL-UNNAMED"
)

val result = convertJavacArgumentsListToMap(args)
result.forEach { (key, value) -> println("Key: $key Value: $value") }
Key: -verbose Value: 
Key: -cp Value: path/to/classes
Key: -J-Xmx512m Value: 
Key: -g:none Value: 
Key: -source Value: 1.8
Key: --add-opens Value: java.base/java.util=ALL-UNNAMED
``` 

@tschuchortdev
Copy link
Owner

Thanks for your PR! Does this fix the issue you were having in #385, i.e. did you confirm that the options are actually passed to kapt correctly? It would be good to have at least one test to exercise this, but --enable-preview probably can't be used because it is not available in earlier JDK versions. Perhaps it is sufficient to search the logs for javac options passed to kapt.

@GavinRay97
Copy link
Contributor Author

No problem =)

Does this fix the issue you were having in #385, i.e. did you confirm that the options are actually passed to kapt correctly?

It does, the code runs without issue after this patch 👍

It would be good to have at least one test to exercise this, but --enable-preview probably can't be used because it is not available in earlier JDK versions.

I thought about adding a test but like you said, it would mean forcing the JDK to something like a minimum of JDK 17 or so for --enable-preview

Perhaps it is sufficient to search the logs for javac options passed to kapt.

Good idea -- this sounds reasonable to me 👍

@tschuchortdev tschuchortdev merged commit 8212e5e into tschuchortdev:master May 26, 2024
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.

Adding --enable-preview to javacArguments does not work. How to properly do this?
2 participants