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

Gradle dsl to specify the mainClass for protocPlugin #738

Open
wants to merge 6 commits into
base: master
Choose a base branch
from

Conversation

016K
Copy link

@016K 016K commented Nov 8, 2023

#455 Solve this problem

I encountered this issue when using dubbo generation

Copy link

google-cla bot commented Nov 8, 2023

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

@@ -104,8 +105,8 @@ class ToolsLocator {
group:groupId,
name:artifact,
version:version,
classifier:classifier ?: osdetector.classifier,
ext:extension ?: 'exe',
classifier:classifier ?: mainClass ? null : osdetector.classifier,
Copy link
Collaborator

Choose a reason for hiding this comment

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

mainClass should virtually never be specified. In your specific case for dubbo it makes some sense, as the JAR has multiple generators inside. But the recommendation is "the JAR should be stand-alone, with main-class specified in the meta-inf". So I doubt we want these two lines of convenience, as it creates a perverse incentive.

Copy link
Author

Choose a reason for hiding this comment

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

If mainClass can be specified, it will be more convenient to use.

Copy link
Author

Choose a reason for hiding this comment

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

I am currently in urgent need of this feature. Without it, I may need to maintain multiple jars separately to complete it, and others may also need to find other ways to solve this problem

Copy link
Collaborator

Choose a reason for hiding this comment

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

I do not want to encourage mainClass; most cases there should only be a single class. Allowing alternative classes and encouraging never having Main-Class in the jar are two very different things.

Copy link
Author

Choose a reason for hiding this comment

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

image
image

How should I specify classifier as null

Copy link
Author

Choose a reason for hiding this comment

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

I used translation software which may not convey the message accurately.

Copy link
Collaborator

Choose a reason for hiding this comment

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

The problem isn't limited to "allowing alternative classes to be the main class." The problem you're seeing looks to impact all usages of jars. My point here is I don't want behavior tied to overriding the main class. Whatever solution here is needed should also be available when using the main-class from inside the jar.

Taking a look at ServiceTalk, it looks like they are just specifying a classifier (io.servicetalk:servicetalk-grpc-protoc:$serviceTalkVersion:all@jar). They were the ones that added jar support to the plugin, so I guess they just didn't need null classifier. Since the gradle shadow plugin does encourage you to publish both "jar without dependencies" and the fat jar, I guess that makes some sense.

Do you only need dubbo-compiler support? It looks like their jar doesn't include dependencies, so I don't think the null classifier would have worked. I'm impressed that Dubbo has gone out of their way to make the exe's.

Copy link
Author

Choose a reason for hiding this comment

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

image
image
image
If I want to use a jar, but this jar does not have a classifier, it will be forced to specify a classifier by osdetector.classifier. In fact, many jars do not have a classifier. In this case, ar cannot be selected at all.

classifier:classifier ?: mainClass ? null : osdetector.classifier,
Actually, I want jars that do not need classifier to not be overwritten by osdetector.classifier

Copy link
Collaborator

Choose a reason for hiding this comment

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

I understand theoretically wanting a null classifier. But specifically for dubbo-compiler it seems to be pointless, as dubbo-compiler isn't a fat jar. What plugin are you wanting to use here? Is it dubbo-compiler, or something else?

Copy link
Author

Choose a reason for hiding this comment

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

Yes, I want to use dubbo compiler. I have recompiled a complete jar in my private library

Copy link
Collaborator

@ejona86 ejona86 left a comment

Choose a reason for hiding this comment

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

The code looks fine. Just need to iron out the README. Either an example that uses a fat jar or just don't update the README.

@@ -184,6 +184,11 @@ protobuf {
     // or
     // path = 'tools/protoc-gen-grpc-java'
   }
dubbo {
artifact = "org.apache.dubbo:dubbo-compiler:${dubboVersion}"
Copy link
Collaborator

Choose a reason for hiding this comment

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

Since this doesn't actually work for other people, I don't think it makes sense as an example. Looks like we don't have an example already for jar files? Oh, well. servicetalk might be a fair example if we were searching for one.

@016K
Copy link
Author

016K commented May 14, 2024

image image image

I have successfully verified it locally. How can I solve this problem

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.

2 participants