Skip to content

Commit

Permalink
Fix proto with proto-libraries, refactor errorprone
Browse files Browse the repository at this point in the history
Refactor errorprone

Fix building protos in Gradle
commit_hash:54d1cdf9df00e7ab30b991ddf1f534ab5992ef3c
  • Loading branch information
dimdim1177 committed Nov 21, 2024
1 parent 955d00e commit e301825
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 26 deletions.
41 changes: 17 additions & 24 deletions build/export_generators/ide-gradle/build.gradle.kts.jinja
Original file line number Diff line number Diff line change
Expand Up @@ -38,21 +38,6 @@ subprojects {
{%- endif %}

plugins {
{#- some plugins configuration -#}
{%- for library in target.consumer if library.classpath -%}
{#- error prone plugin configuration -#}
{%- if library.prebuilt and library.jar and (library.type != "contrib" or build_contribs) and "contrib/java/com/google/errorprone/error_prone_annotations/" in library.jar -%}

id("net.ltgt.errorprone") version "{{ errorprone_plugin_version }}"

{%- endif -%}
{%- endfor -%}

{#- lombok configuration -#}
{#- TODO remove usings annotation_processors semantic -#}
{%- if ("lombok.launch.AnnotationProcessorHider$AnnotationProcessor" in target.annotation_processors) or (target.use_annotation_processor|length and target.use_annotation_processor|select('startsWith', 'contrib/java/org/projectlombok/lombok')|length) %}
id("io.freefair.lombok") version "8.6"
{%- endif -%}
{%- if mainClass %}
`application`
{%- else %}
Expand All @@ -76,6 +61,17 @@ plugins {
{%- if target.with_kotlinc_plugin_serialization|length %}
kotlin("plugin.serialization") version "{{ kotlin_version }}"
{% endif -%}
{%- endif -%}

{#- errorprone plugin configuration -#}
{%- if target.consumer|selectattr('jar', 'startsWith', 'contrib/java/com/google/errorprone/error_prone_annotations')|length %}
id("net.ltgt.errorprone") version "{{ errorprone_plugin_version }}"
{%- endif -%}

{#- lombok plugin configuration -#}
{#- TODO remove usings annotation_processors semantic -#}
{%- if ("lombok.launch.AnnotationProcessorHider$AnnotationProcessor" in target.annotation_processors) or (target.use_annotation_processor|length and target.use_annotation_processor|select('startsWith', 'contrib/java/org/projectlombok/lombok')|length) %}
id("io.freefair.lombok") version "8.6"
{%- endif %}
}

Expand Down Expand Up @@ -272,6 +268,7 @@ sourceSets.main.java.srcDirs += "{{ srcdir_glob[0] }}"
{%- endfor -%}

sourceSets {
{%- if target.runs|length %}
main {
{#-
Default by Gradle:
Expand All @@ -280,13 +277,11 @@ sourceSets {
resources.srcDir("src/main/resources")
#}
{%- if target.runs|length -%}
{%- for run in target.runs -%}
{{ OutDirs(run, ' java.srcDir("', '")') }}
{%- endfor -%}
{%- endif %}
{%- endfor %}
}

{%- endif %}
test {
{#-
Default by Gradle:
Expand Down Expand Up @@ -315,11 +310,9 @@ sourceSets {

dependencies {
{%- for library in target.consumer if library.classpath -%}
{# error prone plugin configuration #}
{%- if library.prebuilt and library.jar and (library.type != "contrib" or build_contribs) and "contrib/java/com/google/errorprone/error_prone_annotations" in library.jar -%}
{% set errorprone_version = library.jar -%}
{% set errorprone_parts = errorprone_version|replace("contrib/java/com/google/errorprone/error_prone_annotations/") -%}
{% set errorprone_parts = split(errorprone_parts, '/') %}
{%- if library.prebuilt and (library.type != "contrib" or build_contribs) and ("contrib/java/com/google/errorprone/error_prone_annotations" in library.jar) -%}
{%- set errorprone_version = library.jar|replace("contrib/java/com/google/errorprone/error_prone_annotations/", "") -%}
{%- set errorprone_parts = split(errorprone_version, '/', 2) %}
errorprone("com.google.errorprone:error_prone_core:{{ errorprone_parts[0] }}")
{%- endif -%}

Expand Down
46 changes: 44 additions & 2 deletions build/export_generators/ide-gradle/build.gradle.kts.proto.jinja
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
{%- set publish = target.publish -%}
{%- set libraries = target.consumer|selectattr('type', 'eq', 'library') -%}

import com.google.protobuf.gradle.*

val baseBuildDir = "{{ export_root }}/gradle.build/"
Expand All @@ -7,6 +9,11 @@ subprojects {
buildDir = file(baseBuildDir + project.path.replaceFirst(":", "/").replace(":", "."))
}

val mainProtosDir = File(buildDir, "main_protos")
{%- if libraries|length %}
val mainExtractedIncludeProtosDir = File(buildDir, "extracted-include-protos/main")
{%- endif %}

plugins {
id("java-library")
id("com.google.protobuf") version "0.8.19"
Expand Down Expand Up @@ -99,8 +106,13 @@ dependencies {
}
{%- endif -%}
{%- endif -%}
{%- endfor %}
protobuf(files("$projectDir"))
{%- endfor -%}

{%- if target.proto_namespace %}
protobuf(files(File(mainProtosDir, "{{ target.proto_namespace }}")))
{%- else %}
protobuf(files(mainProtosDir))
{%- endif %}
}

protobuf {
Expand Down Expand Up @@ -141,6 +153,36 @@ protobuf {
{%- endif %}
}

val prepareMainProtos = tasks.register<Copy>("prepareMainProtos") {
from("$project_root") {
{#- list of all current project proto files -#}
{%- for proto in target.proto_files %}
include("{{ proto }}")
{%- endfor %}
}
into(mainProtosDir)
}

{% if libraries|length -%}
val extractMainLibrariesProtos = tasks.register<Copy>("extractMainLibrariesProtos") {
from("$project_root") {
{#- list of all library directories -#}
{%- for library in libraries -%}
{%- set path_and_jar = rsplit(library.jar, '/', 2) %}
include("{{ path_and_jar[0] }}/**/*.proto")
{%- endfor %}
}
into(mainExtractedIncludeProtosDir)
}

{% endif -%}
afterEvaluate {
tasks.getByName("extractProto").dependsOn(prepareMainProtos)
{%- if libraries|length %}
tasks.getByName("extractProto").dependsOn(extractMainLibrariesProtos)
{%- endif %}
}

{# To avoid problems when build project with proto #}
tasks.getByName("sourcesJar").dependsOn("generateProto")

Expand Down

0 comments on commit e301825

Please sign in to comment.