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

Support java modules for thrift #6076

Merged
merged 2 commits into from
Feb 19, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions gradle/scripts/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -695,8 +695,16 @@ and artifact ID. For example:

If enabled, each project with `java` flag will have the `automaticModuleName` property.

You can override the automatic module name of a certain project via the `automaticModuleNameOverrides`
extension property:
You can override the automatic module name of a certain project via `automaticModuleNameOverride`:

```groovy
ext {
// Change the automatic module name of a project to 'com.example.fubar'.
automaticModuleNameOverride = 'com.example.fubar'
}
```

Alternatively, you can also specify a mapping via the `automaticModuleNameOverrides` extension property:

```groovy
ext {
Expand Down
41 changes: 28 additions & 13 deletions gradle/scripts/lib/common-info.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -73,20 +73,35 @@ allprojects {
return null
}

// Use the overridden one if available.
def overriddenAutomaticModuleName = findOverridden('automaticModuleNameOverrides', project)
if (overriddenAutomaticModuleName != null) {
return overriddenAutomaticModuleName
}
return project.provider {
// per-project override
if (project.ext.has('automaticModuleNameOverride')) {
def override = project.ext.get('automaticModuleNameOverride')
if (!(override instanceof String)) {
throw new IllegalStateException("project.ext.automaticModuleNameOverride must be a String: ${override}")
}
return override
}

// Use the overridden one if available.

// Generate from the groupId and artifactId otherwise.
def groupIdComponents = String.valueOf(rootProject.group).split("\\.").toList()
def artifactIdComponents =
String.valueOf(project.ext.artifactId).replace('-', '.').split("\\.").toList()
if (groupIdComponents.last() == artifactIdComponents.first()) {
return String.join('.', groupIdComponents + artifactIdComponents.drop(1))
} else {
return String.join('.', groupIdComponents + artifactIdComponents)
def overriddenAutomaticModuleName = findOverridden('automaticModuleNameOverrides', project)
if (overriddenAutomaticModuleName != null) {
return overriddenAutomaticModuleName
}

// Generate from the groupId and artifactId otherwise.
def groupIdComponents = String.valueOf(rootProject.group).split("\\.").toList()
def artifactIdComponents =
String.valueOf(project.ext.artifactId).replace('-', '.').split("\\.").toList()
def generatedName
if (groupIdComponents.last() == artifactIdComponents.first()) {
generatedName = String.join('.', groupIdComponents + artifactIdComponents.drop(1))
} else {
generatedName = String.join('.', groupIdComponents + artifactIdComponents)
}
generatedName = generatedName.replaceAll("\\.(\\d)", "_\$1")
return generatedName
}
}.call()
}
Expand Down
6 changes: 4 additions & 2 deletions gradle/scripts/lib/java-shade.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,10 @@ configure(relocatedProjects) {

// Set the 'Automatic-Module-Name' property in MANIFEST.MF.
if (project.ext.automaticModuleName != null) {
manifest {
attributes('Automatic-Module-Name': project.ext.automaticModuleName)
doFirst {
manifest {
attributes('Automatic-Module-Name': project.ext.automaticModuleName.get())
}
}
}
}
Expand Down
6 changes: 4 additions & 2 deletions gradle/scripts/lib/java.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -166,8 +166,10 @@ configure(projectsWithFlags('java')) {
// Set the 'Automatic-Module-Name' property in 'MANIFEST.MF' if `automaticModuleName` is not null.
if (project.ext.automaticModuleName != null) {
tasks.named('jar') {
manifest {
attributes('Automatic-Module-Name': project.ext.automaticModuleName)
doFirst {
manifest {
attributes('Automatic-Module-Name': project.ext.automaticModuleName.get())
}
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion thrift/thrift0.13/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ dependencies {
// Use the old compiler.
def thriftFullVersion = libs.thrift013.get().versionConstraint.requiredVersion
ext {
thriftVersion = thriftFullVersion.substring(0, thriftFullVersion.lastIndexOf('.'));
thriftVersion = thriftFullVersion.substring(0, thriftFullVersion.lastIndexOf('.'))
}

// Keep the original Guava references in ThriftListenableFuture,
Expand Down
Loading