Skip to content

WIP: AVRO-4223 Gradle plugin for generating Java code#3614

Open
frevib wants to merge 99 commits intoapache:mainfrom
frevib:AVRO-4223-gradle-plugin
Open

WIP: AVRO-4223 Gradle plugin for generating Java code#3614
frevib wants to merge 99 commits intoapache:mainfrom
frevib:AVRO-4223-gradle-plugin

Conversation

@frevib
Copy link

@frevib frevib commented Jan 5, 2026

What is the purpose of the change

Gradle plugin to generate Java code from Avro files

Verifying this change

This change added tests and can be verified as follows:

cd to avro/lang/java/gradle-plugin

./gradlew test

Documentation

Release

https://plugins.gradle.org/plugin/eu.eventloopsoftware.avro-gradle-plugin

0.0.2 is released and fully works with AVSC files:

0.0.5

0.0.8

0.1.0 this release adds Protocol support.

0.1.1 Fix issue with Gradle multi project, where sources would not appear on the classpath

Installation instructions: https://github.com/frevib/avro/blob/AVRO-4223-gradle-plugin/lang/java/gradle-plugin/README.md#version

An official release will be done in the coming month

Refactor
Release 0.1.0
@frevib
Copy link
Author

frevib commented Jan 26, 2026

Avro gradle plugin 0.1.0 is released: https://plugins.gradle.org/plugin/eu.eventloopsoftware.avro-gradle-plugin

Protocol support has been added in this release

@frevib
Copy link
Author

frevib commented Jan 27, 2026

@raphaelauv did you test the latest release https://plugins.gradle.org/plugin/eu.eventloopsoftware.avro-gradle-plugin? No need to add compileJava.source(avroGenerateJavaClasses) any more.

Copy link
Contributor

@opwvhk opwvhk left a comment

Choose a reason for hiding this comment

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

This is yet another marked improvement. Thank you!

I have a few open comments, and we'll want to fix the build, but otherwise I'm happy with the result.

Improve docs on add sources from JAR files
Add license files
Format with Spotless
Add Spotless config
Format
Format
@frevib frevib marked this pull request as ready for review February 2, 2026 15:42
Format
@martin-g
Copy link
Member

martin-g commented Feb 3, 2026

I have created https://issues.apache.org/jira/browse/INFRA-27616 for the requirement from Gradle to prove the ownership of avro.apache.org DNS domain.

private fun instantiateAdditionalVelocityTools(velocityToolsClassesNames: List<String>): List<Any> {
return velocityToolsClassesNames.map { velocityToolClassName ->
try {
Class.forName(velocityToolClassName).getDeclaredConstructor().newInstance()
Copy link
Member

Choose a reason for hiding this comment

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

Why this uses the current class' loader ?
loadLogicalTypesFactories() and doCompile() use the thread's class loader

Copy link
Author

Choose a reason for hiding this comment

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

I've used the same as in the Maven plugin:

Class<?> klass = Class.forName(velocityToolClassName);

and:

protected URLClassLoader createClassLoader() throws DependencyResolutionRequiredException, MalformedURLException {

compileSchemaTask.protocolFiles.from(
project.fileTree(sourceDirectory).apply {
setIncludes(includesProtocol)
setExcludes(extension.excludes.get())
Copy link
Member

Choose a reason for hiding this comment

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

Same here - testExcludes

Copy link
Author

@frevib frevib Mar 21, 2026

Choose a reason for hiding this comment

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

We're not making a distinction between main and test includes/excludes like in the Maven plugin. If you compile for the test classpath, the same value is used from includedSchemaFiles, excludedSchemaFiles, includedProtocolFiles and excludedProtocolFiles.

It's a bit of design choice, but I thought it's a bit unnecessary to have this distinction. Thoughts?

</execution>
<execution>
<id>run-gradle-task-publish</id>
<phase>deploy</phase>
Copy link
Member

Choose a reason for hiding this comment

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

We use deploy to deploy -SNAPSHOTs for the Maven artefacts.
AFAIK Gradle plugins repo does not allow -SNAPSHOTs

Copy link
Author

@frevib frevib Mar 21, 2026

Choose a reason for hiding this comment

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

Correct, the Gradle plugin portal does not support snapshots. It works different than Sonatype, where you first push and later release via the Sonatype UI. With the Gradle publish plugin when you run ./gradlew publishPlugins you'll immediately publish the plugin to the portal.

You can however publish -SNAPSHOT to the local Maven repo with ./gradlew publishToMavenLocal

@frevib frevib requested a review from Sineaggi February 16, 2026 07:37
Fix source directory
Fix bug with source dependencies
Release 0.1.1
Update Kotlin plugin

Update readme
Remove unused testExcludes

Use excludes from configuration
Use GradleException
Fix deprecated API
Clarify docs
Update Javadoc

Cleanup unneeded code
Bump version
Add release information
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

build Java Pull Requests for Java binding

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants