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

Configuration options to (de)activate the plugin for selected Configurations and Source Sets #134

Open
tg-freigmbh opened this issue Jul 29, 2024 · 5 comments
Labels
enhancement New feature or request

Comments

@tg-freigmbh
Copy link

Hello.
So A bit of context: I am pulling artifacts together, so they can be put in a native (outside of gradle) installer.
I am doing this using a configuration, and adding the dependencies to the configuration.
Now I still need to add the extraJavaModuleInfo to project, or else I will untransformed jars without jpms infos and that wont work.

However the plugin currently only registers itself with configurations that are related to sourceSets my configurations isnt related to one..
After skimming through the code it seems there is an Attribute "javaModules" of type Boolean, so I thought maybe i can use that.


val gimme by configurations.registering{
    isCanBeConsumed=false
    attributes{
        attribute(Attribute.of("javaModule", Boolean::class.java),true )

Howerver that gives me

Build file 'G:\development\java21\blub\zInstaller\Setup-JournalReportingTool2\External-Artifacts\build.gradle.kts' line: 9

Could not create domain object 'gimme' (Configuration)
> Unexpected type for attribute 'javaModule' provided. Expected a value of type boolean but found a value of type java.lang.Boolean.

And it seems like kotlins boolean handling is an absolute nightmare and there is no way to get a correct primitive java boolean... as a workaround i am gonna try to add an empty dummy sourceset tomorrow and see if that gets me somewhere .
Best regards

@jjohannes
Copy link
Member

Hi, I'll give more feedback on this later.

In general, the type you need to use for the attribute in Kotlin is Boolean::class.javaObjectType.

Hope this helps.

@tg-freigmbh
Copy link
Author

Ah many thanks, cant believe i spend like an hour trying all kind of ai generenated nonsense to get this boolan nonsense to work, but couldnt find this syntax ;)

@tg-freigmbh
Copy link
Author

Ok I got my setup running, but probably would recommend my aproach; it can be a bit confusing how gradle handles variant selection slightly different than "normal"

@tg-freigmbh
Copy link
Author

tg-freigmbh commented Jul 31, 2024

And now I also got the usecase that my project actually is a java project, but because this Plugin implecetly activates itself for all source sets, it also also integrates itself with a source set that will break and I cant easily migrate. As a workaround i can split my project, but its a bit akward.

@jjohannes
Copy link
Member

For reference - the topic is currently documented in the README:
https://github.com/gradlex-org/extra-java-module-info#how-do-i-deactivate-the-plugin-functionality-for-a-certain-classpath

As this issue shows, it's quite awkward to use, especially because of the Boolean::class.javaObjectType attribute.

I think the plugin extension could offer an easier DSL/API for this. Something like:

extraJavaModuleInfo {
  deactivateForSourceSet(sourceSets.test)
  deactivateForConfiguration(configurations.annotationProcessor)
  activateForConfiguration(configurations.myOwn)
}

@jjohannes jjohannes changed the title Feature Request: (mabye) make this Plugin more useable if the Project is not a java project/ doesnt have source sets. Configuration options to (de)activate the plugin for selected Configurations and Source Sets Aug 19, 2024
@jjohannes jjohannes added the enhancement New feature or request label Aug 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants