quarkusio / quarkus

Quarkus: Supersonic Subatomic Java.
https://quarkus.io
Apache License 2.0
13.36k stars 2.56k forks source link

[Extension Proposal] Enforcer extension #41443

Open gastaldi opened 1 week ago

gastaldi commented 1 week ago

Description

The idea of this extension is analogous to the Maven Enforcer Plugin: introduce Build Items to control certain environmental constraints such as Quarkus version, JDK version, and OS family along with many more built-in rules and user created rules.

Also a potential solution for #37169

Interested in this extension, please +1 via the emoji/reaction feature of GitHub (top right).

Repository name

quarkus-enforcer

Short description

Control certain environmental constraints and fail the build if they don't match

Repository Homepage URL

https://docs.quarkiverse.io//dev/

Repository Topics

Team Members

Additional context

No response

quarkus-bot[bot] commented 1 week ago

/cc @aloubyansky (extension-proposal), @gsmet (extension-proposal), @maxandersen (extension-proposal)

aloubyansky commented 1 week ago

How would that work as an extension?

gastaldi commented 1 week ago

@aloubyansky I thought of introducing a MinimumQuarkusVersionBuildItem which other extensions could produce and we perform the check here in a build step, failing the build (or logging a warning) if the expected version doesn't match

aloubyansky commented 1 week ago

This is a kind of static config validation. Ideally this kind of validation should be performed before the augmentation process starts.

gastaldi commented 1 week ago

Right, I haven't yet checked if it might need some changes in core to allow that, but I agree

aloubyansky commented 1 week ago

We have a few other validation checks in this category that are performed in build steps. @dmlloyd would you like to get them moved to pre-augmentation phase?

aloubyansky commented 1 week ago

I think it may justify some changes in core. Specifically, we could introduce a proper config validation phase. That would include version alignment checks (currently we check platform member bom version alignment), possibly capability requirements check (required and provided + conflicts).

dmlloyd commented 1 week ago

I think that would make sense.

geoand commented 1 week ago

What problem is this new extension going to solve?

gastaldi commented 1 week ago

@geoand one use case is that extensions could specify the minimum Quarkus version they require to function (because they use an APi introduced from that version onwards). This would hopefully avoid CNFE and method signature errors during the application's build time

geoand commented 1 week ago

That makes perfect sense, but is an extension the proper way to do this, or would the changes in the core that Alexey mentions suffice?

gastaldi commented 1 week ago

I am not sure yet what changes in core would need to be done to support this. My initial idea was so that extensions would produce BuildItems for the environment they would require and we'd consume them and fail the build if there is a mismatch

geoand commented 1 week ago

My feeling is that we could support this functionality without an extension, as it would essentially be static information that does not have to interact with the rest of the build - just prevent it if need be :)

maxandersen commented 1 week ago

Like others I'm not following how this would be useful as independent extension or are you assuming core will depend on it?

gastaldi commented 1 week ago

Because an extension would (in theory) not require changes in core and would work when an extension depending on it is included in an app using any existing Quarkus version

aloubyansky commented 1 week ago

@gastaldi do i remember correctly that you mentioned there was a "min Quarkus version" field in extension metadata already? Could you please link to an example? Thanks.

gastaldi commented 1 week ago

@aloubyansky sorry I wasn't clear, I meant that we have the built-with-quarkus-core: "3.8.4" in the quarkus-extension.yaml metadata, not the minimum Quarkus version an extension supports

aloubyansky commented 1 week ago

ok, so the question is how extensions would declare their Quarkus version compatibility compatibility requirements. Build items or metadata. Both would be pretty much be fixed at extension build time, which is a limitation when it comes to not yet released Quarkus versions. Either way, I would prefer metadata as the source of this data.

geoand commented 1 week ago

Either way, I would prefer metadata as the source of this data.

Definitely +1

gastaldi commented 1 week ago

How about we introduce a quarkus-core-compatibility: [3.8.4,) metadata featuring a version range that could be checked somewhere in core?

Default would be [${built-with-quarkus-core},)

aloubyansky commented 1 week ago

A version range would be a natural first step. BTW, don't we have the next Quarkus major version as the upper limit when displaying extensions on code.quarkus or even in the registry?

I don't think we want to default to [${built-with-quarkus-core},) exactly, since that will put a limit on the micro version, which is updated often. We should probably be defaulting to major.minor.0, which seems to be too limiting too considering the frequency of releases. Tricky...

gastaldi commented 1 week ago

Maybe use streams instead (no patch version). In theory we shouldn't introduce API changes in patch releases, but who knows :)