GoogleContainerTools / jib

🏗 Build container images for your Java applications.
Apache License 2.0
13.52k stars 1.42k forks source link

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

Open HappyHacker123 opened 3 months ago

HappyHacker123 commented 3 months ago

Environment:

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.

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 commented 3 months ago

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

chanseokoh commented 3 months ago

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 commented 3 months ago

@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.