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

Some dependencies in jib-core are set to wrong dependency scope that may cause compilation error. #4234

Open
HappyHacker123 opened this issue Apr 8, 2024 · 3 comments

Comments

@HappyHacker123
Copy link

HappyHacker123 commented Apr 8, 2024

Environment:

  • Jib version: 0.27.0
  • Build tool: Gradle 8.4.0

Description of the issue:
The following dependencies in jib-core are set to scoep implementation, but the expected scope should api.

  implementation dependencyStrings.JACKSON_DATABIND
  implementation dependencyStrings.GUAVA
  implementation dependencyStrings.COMMONS_COMPRESS
  implementation dependencyStrings.GOOGLE_HTTP_CLIENT

According to gradle offcial doc,if a library contains classes that are exposed in the library binary interface, its dependency scope should be api. The above depedencies all contain classes exposed in binary interface as offical doc goes, I list one example of each dependency below.

  • Class JsonDeserializer in JACKSON_DATABIND is extended by jib-core/src/main/java/com/google/cloud/tools/jib/image/json/DescriptorDigestDeserializer.java
  • Class ListMultimap in GUAVA is used as public method parameter in jib-core/src/main/java/com/google/cloud/tools/jib/configuration/BuildContext.java
  • Class TarArchiveEntry in COMMONS_COMPRESS is used as public method parameter in jib-core/src/main/java/com/google/cloud/tools/jib/tar/TarStreamBuilder.java
  • Class HttpContent in GOOGLE_HTTP_CLIENT is implemented in jib-core/src/main/java/com/google/cloud/tools/jib/http/BlobHttpContent.java

Expected behavior:
The dependencies scope should be changed to api. Otherwise it can lead to compilation failures in consumers, as mentioned in offical doc. I will give an example to reproduce below.

Steps to reproduce:
Import jib-core as a dependency in a project and try to access BlobHttpContent like the below class. Compilation will fail due to GOOGLE_HTTP_CLIENT is set to implementation and not api.

import com.google.cloud.tools.jib.http.BlobHttpContent;

public class Main extends BlobHttpContent {
    public Main(Blob blob, String contentType) {
        super(blob, contentType);
    }

    public static void main(String[] args) {
        System.out.println("Hello world!");
    }
}
    implementation("com.google.cloud.tools:jib-core:0.27.0")
图片
@HappyHacker123 HappyHacker123 changed the title Some dependencies in jib-core are set to wrong dependency scope, leading to compilation error. Some dependencies in jib-core are set to wrong dependency scope that may cause compilation error. Apr 8, 2024
@HappyHacker123
Copy link
Author

@blakeli0 @alicejli Could you help me review this issue? Many thanks :)

@chanseokoh
Copy link
Member

chanseokoh commented Apr 8, 2024

First of all, you are not supposed to use or access BlobHttpContent. The intention is that only those classes under the api directiory are the public surface of the jib-core library.

(However, I admit I may not be understanding the gist of this issue.)

@HappyHacker123
Copy link
Author

@chanseokoh Thanks for your prompt reponese :).

Actually i'm mainly talking about the listed dependencies should be set to configuration api instead of implementation. The example of BlobHttpContent is just showing possible consequence of wrong configuration. Below are gradle official doc on api dependencies.

So when should you use the api configuration? An API dependency is one that contains at least one type that is exposed in the library binary interface, often referred to as its ABI (Application Binary Interface). This includes, but is not limited to:

  • types used in super classes or interfaces
  • types used in public method parameters, including generic parameter types (where public is something that is visible to compilers. I.e. , public, protected and package private members in the Java world)
  • types used in public fields
  • public annotation types

According to the doc, there are mainly four situations that the dependency should be set to api. So, in the above issue body, I'm listing where these dependencis meet one of these criteria and thus should be set to api.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants