hashgraph / hedera-services

Crypto, token, consensus, file, and smart contract services for the Hedera public ledger
Apache License 2.0
280 stars 124 forks source link

Proposal: Shared Gradle Convention Plugins for Hedera #14255

Open jjohannes opened 1 month ago

jjohannes commented 1 month ago

Problem

Many repositories in the github.com/hashgraph organization use Gradle to define their project structure and build (compile, test, check, ...) the code. The currently most sophisticated setup is the one in this repository hedera-services. In the past, the configuration in this repository was often copied when new repositories were created. This approach has a number of downsides:

Solution

General solution idea

Gradle plugins can be published to Maven repositories, just as we publish Modules to repositories. Technically, any Maven repository can be used, but there is a "Maven Central for Gradle Plugins" called the "Gradle Plugin Portal" - https://plugins.gradle.org/ - that may be used to publish open-source plugins.

We use the approach of Convention Plugins to configure the Gradle setup already. Technically, Gradle makes no difference between Convention Plugins and other "types" of plugins. Hence, we could publish the plugins we have defined in gradle/plugins/src/main/kotlin in as they are. Then we can reuse them in other repositories.

Most of the convention plugins are not specific to hedera-services already. Which means they are almost good to be reused in another context/repository.

Concrete Proposal:

  1. Go through the plugins in gradle/plugins/src/main/kotlin and make sure to have a set of plugins not specific for hedera-services. This should include splitting the plugins up further to have one plugin for each "aspect" of the build. Consistently name these plugins com.hedera.gradle.convention.<aspect>.gradle.kts. These plugins should work in a way that they can be used independently and individually. (While doing this, also improve documentation #11568.)
    • com.hedera.gradle.conventions.java-compile
    • com.hedera.gradle.conventions.javadoc
    • com.hedera.gradle.conventions.test
    • com.hedera.gradle.conventions.shadow
    • com.hedera.gradle.conventions.jpms
    • com.hedera.gradle.conventions.jmh
    • com.hedera.gradle.conventions.spotless
    • ...
  2. Copy move these plugins to a separate git repository - hedera-gradle-conventions
  3. Locally use the plugins in the following repositories to test the approach. This can locally be done using the includeBuild("...") feature before actually publishing the plugins.
  4. Publish the plugins, to the Gradle Plugin Portal. As the plugins are all opens source, it makes sense to publish them there. A plugin ID like com.hedera.gradle.convention.java-compile can be read as "Hedera's Gradle Conventions for Compiling Java Code" - which other projects (outside of Hedera) could also use. Similar to how we use code formatting styles defined by other orgs/companies. This should be done via GH actions in the new hedera-gradle-conventions repository.
  5. Use the initial version of the published plugins in...

Alternatives

No response

nathanklick commented 1 month ago

We should not publish from the hedera-services repository. These should be defined in their own repository and all publishing should happen via CI under our Gradle Plugins Repository SA.

mxtartaglia-sl commented 1 month ago

Nothing to add here; it is a great idea. Also, I agree with Nathan that it should have its own repository.

rbarkerSL commented 1 month ago

I like this proposal.

jjohannes commented 1 month ago

Thank you all for the feedback. Doing this in a separate Git repo from the start as proposed by @nathanklick sounds good. Not only for the publishing (credentials) and pipeline, but also for having a dedicated place for the Gradle configuration and it's documentation. I think it will make doing documentation and discovering documentation simpler.

I'll adjust the proposal accordingly.

How should the repo be named? https://github.com/hashgraph/hedera-services/hedera-gradle-conventions ? With the publishing coordinates (for the Jar containing the plugins) being com.hedera:hedera-gradle-conventions?

rbair23 commented 1 month ago

@jjohannes give me a few days to work up a good name for this repo.