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

upper-bound-check to work with google-cloud-java's split repository in more generic way #1051

Open
suztomo opened this issue Nov 27, 2019 · 5 comments
Labels
enhancement New feature or request p3

Comments

@suztomo
Copy link
Contributor

suztomo commented Nov 27, 2019

Regarding google-cloud-java's split repositories, as of now the upper-bound-check (https://github.com/googleapis/google-cloud-java/pull/6606/files) does not work for individual libraries, because the libraries-bom only references google-cloud-bom's version. It cannot update individual library's versions referenced by google-cloud-bom.

@chingor13 says:

it seems like we might be able to generalize it to check for arbitrary artifacts with any bom
so like the pubsub repo could check itself in google-cloud-bom

Note that, contrary to upper-bound-check, Linkage Monitor should work for the individual repositories.

@suztomo suztomo changed the title upper-bound-check to work with google-cloud-java's split repo upper-bound-check to work with google-cloud-java's split repository in more generic way Nov 27, 2019
@suztomo
Copy link
Contributor Author

suztomo commented Dec 6, 2019

This check, if implemented, could have detected the typo in google-cloud-errorreporting-bom
googleapis/java-errorreporting#23

@suztomo
Copy link
Contributor Author

suztomo commented Dec 6, 2019

No, it did not. I tested cloud-opensource-java/boms/upper-bounds-check for the latest google-cloud-bom that has com.google.cloud:google-cloud-errorreporting-bom:0.118.0-beta, which contains nonexistent artifact com.google.cloud:grpc-google-cloud-error-reporting-v1beta1. It just ran without causing an error.

Elliotte's finding was on testMaximumLinkageErrors, which builds a class path by downloading the all artifacts in the BOM.

Why upper-bounds-check cannot detect the typo?

When there's a typo in groupID or artifactID, such entries in managed dependencies in BOMs are just unused in the upper-bounds-check.

@suztomo
Copy link
Contributor Author

suztomo commented Dec 6, 2019

For implementation, use properties to specify BOM versions:

suztomo@suxtomo24:~/java-cloud-bom$ git diff
diff --git a/pom.xml b/pom.xml
index 5c163ff..a487a8f 100644
--- a/pom.xml
+++ b/pom.xml
@@ -10,6 +10,9 @@
   <description>
     BOM for google-cloud-java
   </description>
+  <properties>
+    <google.cloud.errorreporting.java.version>0.118.0-beta</google.cloud.errorreporting.java.version>
+  </properties>
   <developers>
     <developer>
       <id>garrettjonesgoogle</id>
@@ -353,7 +356,7 @@
       <dependency>
         <groupId>com.google.cloud</groupId>
         <artifactId>google-cloud-errorreporting-bom</artifactId>
-        <version>0.118.0-beta</version>
+        <version>${google.cloud.errorreporting.java.version}</version>
         <type>pom</type>
         <scope>import</scope>
       </dependency>

@suztomo
Copy link
Contributor Author

suztomo commented Dec 6, 2019

As of now, the upper-bounds-check checks a dependency tree of com.google.cloud:google-cloud-core and com.google.cloud:google-cloud-storage only. The TODO comment says:

TODO is there a way to run this test directly on the BOM instead of
on a pom.xml that imports the BOM?

Enforcer rule's RequireUpperBoundDeps class has following code to get dependencyNode. If this returns a node having the same list of dependencyManagement/dependencies, then upper-bounds-check becomes more generic.

    private DependencyNode getNode( EnforcerRuleHelper helper )
        throws EnforcerRuleException
    {
        try
        {
            MavenProject project = (MavenProject) helper.evaluate( "${project}" );
            DependencyTreeBuilder dependencyTreeBuilder =
                (DependencyTreeBuilder) helper.getComponent( DependencyTreeBuilder.class );
            ArtifactRepository repository = (ArtifactRepository) helper.evaluate( "${localRepository}" );
            ArtifactFactory factory = (ArtifactFactory) helper.getComponent( ArtifactFactory.class );
            ArtifactMetadataSource metadataSource =
                (ArtifactMetadataSource) helper.getComponent( ArtifactMetadataSource.class );
            ArtifactCollector collector = (ArtifactCollector) helper.getComponent( ArtifactCollector.class );
            ArtifactFilter filter = null; // we need to evaluate all scopes
            DependencyNode node =
                dependencyTreeBuilder.buildDependencyTree( project, repository, factory, metadataSource, filter,
                                                           collector );
            return node;
        }

Furthermore, once such enforcer rule exists, BOM's pom.xml can install the enforcer rule. We don't need to setup additional project such as our boms/upper-bounds-check to run the rule.

@suztomo
Copy link
Contributor Author

suztomo commented Dec 6, 2019

@elharo Example failure for google-cloud-bom version 0.101.0-alpha:

suztomo@suxtomo24:~/cloud-opensource-java/boms/upper-bounds-check$ mvn validate -Dgoogle.cloud.java.version=0.101.0-alpha
...
[INFO] --- maven-enforcer-plugin:3.0.0-M2:enforce (enforce) @ upper-bounds-check ---
[WARNING] Rule 0: org.apache.maven.plugins.enforcer.RequireUpperBoundDeps failed with message:
Failed while enforcing RequireUpperBoundDeps. The error(s) are [
Require upper bound dependencies error for com.google.errorprone:error_prone_annotations:2.3.2 paths to dependency are:
+-com.google.cloud.tools.opensource:upper-bounds-check:2.0.0-SNAPSHOT
  +-com.google.cloud:google-cloud-core:1.83.0
    +-com.google.guava:guava:28.1-android (managed) <-- com.google.guava:guava:28.0-android
      +-com.google.errorprone:error_prone_annotations:2.3.2
and
+-com.google.cloud.tools.opensource:upper-bounds-check:2.0.0-SNAPSHOT
  +-com.google.cloud:google-cloud-core:1.83.0
    +-com.google.protobuf:protobuf-java-util:3.11.0 (managed) <-- com.google.protobuf:protobuf-java-util:3.7.1
      +-com.google.errorprone:error_prone_annotations:2.3.3

How about including error_prone_annotations:2.3.2 (old) in BOM?

The enforcer rule still throws error:

[WARNING] Rule 0: org.apache.maven.plugins.enforcer.RequireUpperBoundDeps failed with message:
Failed while enforcing RequireUpperBoundDeps. The error(s) are [
Require upper bound dependencies error for com.google.errorprone:error_prone_annotations:2.3.2 paths to dependency are:
+-com.google.cloud.tools.opensource:upper-bounds-check:2.0.0-SNAPSHOT
  +-com.google.cloud:google-cloud-core:1.83.0
    +-com.google.guava:guava:28.1-android (managed) <-- com.google.guava:guava:28.0-android
      +-com.google.errorprone:error_prone_annotations:2.3.2
and
+-com.google.cloud.tools.opensource:upper-bounds-check:2.0.0-SNAPSHOT
  +-com.google.cloud:google-cloud-core:1.83.0
    +-com.google.protobuf:protobuf-java-util:3.11.0 (managed) <-- com.google.protobuf:protobuf-java-util:3.7.1
      +-com.google.errorprone:error_prone_annotations:2.3.2 (managed) <-- com.google.errorprone:error_prone_annotations:2.3.3

@elharo elharo added the enhancement New feature or request label Feb 7, 2020
@elharo elharo added the p3 label Jul 22, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request p3
Projects
None yet
Development

No branches or pull requests

2 participants