Auto detect main methods inherited from Java sources (including JEP 512 ones) - #4425
Open
Gedochao wants to merge 2 commits into
Open
Auto detect main methods inherited from Java sources (including JEP 512 ones)#4425Gedochao wants to merge 2 commits into
Gedochao wants to merge 2 commits into
Conversation
Collaborator
There was a problem hiding this comment.
Two main things I found:
- First, not caused by this PR:
We don't check whether the main method is protected (and it's not allowed for non JEP512 Java versions). And in result:
public class Test {
protected static void main(String[] args) {
System.out.println("hello");
}
}yields:
./mill -i scala run /tmp/test-repro/Test.java --jvm 17
[...]
Error: Main method not found in class Test, please define the main method as:
public static void main(String[] args)
or a JavaFX application class must extend javafx.application.Application
924/925, 1 FAILED] /Users/jwarchol/Documents/GitHub/scala-cli/millw scala run /tmp/test-repro/Test.java --jvm 17 3s
I'll try to prepare a fix.
EDIT1: #4430
EDIT2: We'll probably have to make sure it works properly in inheritance too. So, imho, it'd probably be best to merge it before this PR, and address it here.
- Second, related to the changes:
package far;
public abstract class FarBase {
static void main(String[] args) {
System.out.println("FarBase.main");
}
}package near;
public abstract class NearBase extends far.FarBase {
private static void main(String[] args) {
System.out.println("NearBase.main");
}
}package near;
public class Child extends NearBase {}results in Child being incorrectly classified as a main class.
4 tasks
Gedochao
marked this pull request as draft
August 18, 2026 12:20
Gedochao
force-pushed
the
feature/detect-inherited-main-methods-2
branch
from
August 18, 2026 12:52
343c469 to
5519ecf
Compare
…12 ones) � Conflicts: � modules/build/src/main/scala/scala/build/internal/MainClass.scala
Gedochao
force-pushed
the
feature/detect-inherited-main-methods-2
branch
from
August 18, 2026 14:01
5519ecf to
8c333e6
Compare
Gedochao
marked this pull request as ready for review
August 19, 2026 11:12
Contributor
Author
|
Rebased on top of #4430 plus added handling for the missing case. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Follow-up to #4418 (comment)
This enables auto-detection of main methods inherited from Java classes/interfaces. Including ones added by JEP 512.
Checklist
scala-cli fmt .)scalafix(./mill -i __.fix)How much have your relied on LLM-based tools in this contribution?
extensively
How was the solution tested?
added automated tests