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

GH-38: Import .proto files from maven dependencies #42

Merged
merged 3 commits into from
Dec 12, 2023

Conversation

ascopes
Copy link
Owner

@ascopes ascopes commented Dec 10, 2023

New features to add the ability to "import" protobuf sources from other locations, including other JARs and other directories, without including them for compilation.

This allows referencing dependencies in a similar way to how Java manages this, and provides the ability to recursively pull in these imports. This has been done because, as an example, depending on com.google.api.grpc:proto-google-common-protos requires protoc to be able to see the protobuf stubs in com.google.protobuf:protobuf-java as well.

Example configuration and output
<plugin>
  <groupId>${plugin-group-id}</groupId>
  <artifactId>${plugin-artifact-id}</artifactId>
  <version>${plugin-version}</version>

  <configuration>
    <additionalImports>
      <additionalImport>mvn:com.google.api.grpc:proto-google-common-protos:2.29.0</additionalImport>
    </additionalImport>
    <protocVersion>${protobuf.version}</protocVersion>
  </configuration>

  <executions>
    <execution>
      <phase>generate-sources</phase>
      <goals>
        <goal>generate</goal>
      </goals>
    </execution>
  </executions>
</plugin>
[INFO] --- protobuf:0.0.2-SNAPSHOT:generate (default) @ example ---
[INFO] Resolving mvn:com.google.protobuf:protoc:3.25.0:exe:linux-x86_64 from Maven repositories
[INFO] Resolved mvn:com.google.protobuf:protoc:3.25.0:exe:linux-x86_64 to local path '/.../protoc-3.25.0-linux-x86_64.exe'
[INFO] Resolving mvn:com.google.api.grpc:proto-google-common-protos:2.29.0:jar from Maven repositories
[INFO] Resolving dependencies of mvn:com.google.api.grpc:proto-google-common-protos:2.29.0:jar from Maven repositories
[INFO] Extracting contents of '/.../protobuf-java-3.25.1.jar' to /.../target/protobuf-extracted/protobuf-java-3.25.1
[INFO] Extracting contents of '/.../proto-google-common-protos-2.29.0.jar' to /.../target/protobuf-extracted/proto-google-common-protos-2.29.0
[INFO] Discovering protobuf sources in /.../src/main/protobuf
[INFO] Discovered a total of 1 protobuf source(s) to compile
[INFO] Invoking [/.../protoc-3.25.0-linux-x86_64.exe, --version]
[INFO] >>> libprotoc 25.0
[INFO] Protoc completed after 7ms with exit code 0
[INFO] Invoking [/.../protoc-3.25.0-linux-x86_64.exe, --proto_path=/.../target/protobuf-extracted/protobuf-java-3.25.1, --proto_path=/.../target/protobuf-extracted/proto-google-common-protos-2.29.0, --proto_path=/.../src/main/protobuf, --java_out=/.../target/generated-sources/protobuf, /.../src/main/protobuf/car.proto]
[INFO] Protoc completed after 3ms with exit code 0

This implementation is a work in progress and may not yet be fully functional for certain cases.

@ascopes ascopes self-assigned this Dec 10, 2023
Copy link

codecov bot commented Dec 10, 2023

Codecov Report

Attention: 12 lines in your changes are missing coverage. Please review.

Comparison is base (cd3147d) 85.82% compared to head (9d57d4f) 86.98%.

Files Patch % Lines
...avenplugin/dependencies/MavenArtifactResolver.java 84.00% 4 Missing ⚠️
.../protobufmavenplugin/generate/SourceGenerator.java 88.57% 3 Missing and 1 partial ⚠️
...obufmavenplugin/dependencies/ArchiveExtractor.java 93.54% 1 Missing and 1 partial ⚠️
...tobufmavenplugin/dependencies/MavenCoordinate.java 94.28% 1 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main      #42      +/-   ##
==========================================
+ Coverage   85.82%   86.98%   +1.15%     
==========================================
  Files          15       18       +3     
  Lines         395      507     +112     
  Branches       27       35       +8     
==========================================
+ Hits          339      441     +102     
- Misses         45       52       +7     
- Partials       11       14       +3     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@ascopes ascopes force-pushed the feature/GH-38-dependencies branch from 2351862 to 9d57d4f Compare December 12, 2023 12:39
@ascopes ascopes marked this pull request as ready for review December 12, 2023 12:43
@ascopes ascopes merged commit 74ad91d into main Dec 12, 2023
8 checks passed
@ascopes ascopes deleted the feature/GH-38-dependencies branch December 12, 2023 12:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant