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

Use the implementation configuration to replace compile #40

Merged
merged 6 commits into from
Jun 9, 2023

Conversation

supl
Copy link
Collaborator

@supl supl commented May 22, 2023

This PR revises the Gradle build system.

It uses the implementation configuration to replace compile.
This is because the compile configuration is deprecated and using the compile configuration doesn't include the dependencies into the jar file.

@supl supl requested a review from feeblefakie May 22, 2023 16:49
@supl supl self-assigned this May 22, 2023
@@ -1,6 +1,6 @@
{
"name": "@scalar-labs/scalar-admin",
"version": "2.1.0",
"version": "2.1.1",
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we update this because now the version of Java and Node are aligned so they have to be updated at the same time.

@@ -102,7 +102,7 @@ targetCompatibility = 1.8

group = "com.scalar-labs"
archivesBaseName = "scalar-admin"
version = "2.1.0"
version = "2.1.1"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it a bug fix? or an improvement? It's labeled as improvement, so they look inconsistent.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, it's a mistake on label.
It should be a bugfix.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I feel it's an improvement.

So after we merge this, are we going to release 2.1.1? Actually, I don't think we need to release it right away.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@brfrn169

Thank you for the advise.

I see. Let me revise it as an improvement.

I was thinking it's a bugfix because:

For example, I am using scalar-admin's RequestCoordinator class in another project scalar-admin-k8s (an additional tool for pausing Scalar products in Kubernetes environemtn).

RequestCoordinator depends on, for an instance, the dnsjava package.

However, because the dnsjava dependency is declared with compile here, so it won't be included in the runtime classpath.

In other words, the scalar-admin-k8s using RequestCoordinator needs to declare dnsjava as a runtime dependency by itself.

This is what I add additionally to the build.gradle of scalar-admin-k8s.

    // FIXME these declarations are due to the drawbacks of using the `compile` configuration in scalar-admin 2.1.0.
    // Remove these declarations when it's fixed in scalar-admin after 2.1.0.
    implementation group: 'javax.json', name: 'javax.json-api', version: '1.1.4'
    implementation group: 'org.glassfish', name: 'javax.json', version: '1.1.4'
    implementation group: 'dnsjava', name: 'dnsjava', version: '3.5.2'
    implementation group: 'io.grpc', name: 'grpc-alts', version: '1.51.0'
    implementation group: 'io.grpc', name: 'grpc-netty', version: '1.51.0'
    implementation group: 'io.grpc', name: 'grpc-protobuf', version: '1.51.0'
    implementation group: 'io.grpc', name: 'grpc-stub', version: '1.51.0'
    implementation group: 'com.google.api.grpc', name: 'proto-google-common-protos', version: '1.0.0'
    implementation group: 'com.google.api.grpc', name: 'googleapis-common-protos', version: '0.0.3'
    implementation group: 'com.google.protobuf', name: 'protobuf-java-util', version: '3.21.12'

(almost copied the whole dependency configuration from scalar-admin)

From scalar-admin-k8s perspective, I feel it's weird to do this because scalar-admin-k8s doesn't directly depends on these packages. The indirected packages should be declared at the library level (scalar-admin) which directly depends on these packages.

I think the issue won't happen in scalardl and scalardb because they only use the gRPC generated classes, and the generated classes depend on grpc-core which is for sure declared in scalardl and scalardb.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds strange. If you declare the dependencies with compileOnly, that would make sense. But if you declare the dependencies with compile, they should be included in the class path.

But, I checked the pom file of scalar-admin-2.1.0, and surprisingly it doesn't have any dependencies:
https://repo1.maven.org/maven2/com/scalar-labs/scalar-admin/2.1.0/scalar-admin-2.1.0.pom

Copy link
Collaborator

@brfrn169 brfrn169 May 25, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For example, this is the build.gradle file for ScalarDB 3.0.0:
https://github.com/scalar-labs/scalardb/blob/v3.0.0/build.gradle

In this file, the dependencies are declared with compile (and testCompile).

And the pom file for this release is as follows:
https://repo1.maven.org/maven2/com/scalar-labs/scalardb/3.0.0/scalardb-3.0.0.pom

The dependencies are included in the dependencies part in pom.xml.

I think that's a normal situation.

Copy link
Collaborator Author

@supl supl May 25, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@brfrn169

Thanks for your hint!

I found the magic occurs between the legacy maven plugin and the current maven-publish plugin. They are in charge of creating POM files.

This is the POM file of scalar-admin 1.1.0
https://repo1.maven.org/maven2/com/scalar-labs/scalar-admin/1.1.0/scalar-admin-1.1.0.pom
(the compile dependencies are there)

and, before 1.2.0, I made this commit to replace the legacy maven plugin with maven-publish
72replacingc8237f7d181b702d99acd63dd3134955110312

it caused the POM file of scalar-admin 1.2.0
https://repo1.maven.org/maven2/com/scalar-labs/scalar-admin/1.2.0/scalar-admin-1.2.0.pom (the dependencies are gone)

It seems that the legacy maven plugin puts the compile dependencies into the POM but the maven-publish plugin doesn't.

And I found a source code snippet of the maven-publish plugin.

https://github.com/gradle/gradle/blob/master/subprojects/maven/src/main/java/org/gradle/api/publish/maven/plugins/MavenPublishPlugin.java#L224

The maven-publish seems to treat the compile dependency as the api dependency, which will not be included in the runtime classpath. Then it explains...

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

By the way, I guess the reason I switched to maven-plugin is in order to publish it to local maven repo and test it with another project.

Copy link
Collaborator

@brfrn169 brfrn169 May 25, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like an api dependency in build.gradle is interpreted as a compile scope dependency in pom.xml.

build.gradle:
https://github.com/scalar-labs/scalardb/blob/v3.9.0/rpc/build.gradle

pom.xml:
https://repo1.maven.org/maven2/com/scalar-labs/scalardb-rpc/3.9.0/scalardb-rpc-3.9.0.pom

So the maven-publish plugin just ignores the compile dependencies in build.gradle? That's weird...

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@supl supl added bug Something isn't working and removed improvement labels May 24, 2023
@supl supl requested a review from feeblefakie May 24, 2023 08:14
compile group: 'io.grpc', name: 'grpc-stub', version: "${grpcVersion}"
compile group: 'com.google.protobuf', name: 'protobuf-java-util', version: "${protobufVersion}"
compile group: 'dnsjava', name: 'dnsjava', version: '2.1.9'
implementation group: 'org.slf4j', name: 'slf4j-api', version: "${slf4jVersion}"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about using the short format?

Suggested change
implementation group: 'org.slf4j', name: 'slf4j-api', version: "${slf4jVersion}"
implementation "org.slf4j:slf4j-api:${slf4jVersion}"

Copy link
Collaborator Author

@supl supl May 25, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the advise!

I revise it in cd2c4b1

Please take a look 🙇

@@ -102,7 +102,7 @@ targetCompatibility = 1.8

group = "com.scalar-labs"
archivesBaseName = "scalar-admin"
version = "2.1.0"
version = "2.1.1"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I feel it's an improvement.

So after we merge this, are we going to release 2.1.1? Actually, I don't think we need to release it right away.

@supl supl requested a review from brfrn169 May 25, 2023 02:28
@supl supl added improvement and removed bug Something isn't working labels May 25, 2023
@feeblefakie
Copy link
Contributor

@supl What should we do for this PR?

@supl
Copy link
Collaborator Author

supl commented Jun 7, 2023

@supl What should we do for this PR?

@feeblefakie
@brfrn169

Sorry for taking so long.

Regarding the feedback from Toshi
#40 (comment)

I was trying to find why the maven-publish plugin ignores the dependencies with the compile configurations in these days but I still couldn't find it.

However, I think it's a correct change to replace the compile configuration by the implementation configuration because:

  • maven-publish plugin works fine with it
  • the compile configuration is deprecated after Gradle 7.0 after all

So, I think I will stop digging the maven-publish plugin and just use the implementation to fix the drawback (the dependencies are not included in the POM file)

Copy link
Collaborator

@brfrn169 brfrn169 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Left one comment. Other than that, LGTM! Thank you!

java/build.gradle Outdated Show resolved Hide resolved
Co-authored-by: Toshihiro Suzuki <brfrn169@gmail.com>
@supl supl added bugfix and removed improvement labels Jun 7, 2023
@supl
Copy link
Collaborator Author

supl commented Jun 7, 2023

I also change the version of the node package to 2.1.1 to align the Java's version.
c483aa3

@feeblefakie
Copy link
Contributor

@supl What should we do about this? Is it OK with the bugfix label?

@supl
Copy link
Collaborator Author

supl commented Jun 9, 2023

@supl What should we do about this? Is it OK with the bugfix label?

@feeblefakie

I think we can merge it and it should be a bugfix.

@feeblefakie feeblefakie merged commit d2d1ee3 into main Jun 9, 2023
1 check passed
@feeblefakie feeblefakie deleted the use-implementation branch June 9, 2023 15:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants