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

Running a project with a main class from IntelliJ when project is built using gradle fails #10961

Open
juanmbellini opened this issue Jul 24, 2020 · 12 comments
Labels
area/gradle Gradle kind/bug Something isn't working

Comments

@juanmbellini
Copy link

juanmbellini commented Jul 24, 2020

Describe the bug
(Describe the problem clearly and concisely.)

After downloading a generated project from the quarkus website (https://code.quarkus.io/), using gradle as build tool, and adding a "main" class according to https://quarkus.io/guides/lifecycle#the-main-method, and trying to run from IntelliJ (just clicking the "play" button next to the main method), makes the application startup fail with the following stacktrace:

Exception in thread "main" java.lang.RuntimeException: java.lang.reflect.InvocationTargetException
	at io.quarkus.launcher.QuarkusLauncher.launch(QuarkusLauncher.java:50)
	at io.quarkus.runtime.Quarkus.launchFromIDE(Quarkus.java:93)
	at io.quarkus.runtime.Quarkus.run(Quarkus.java:79)
	at io.quarkus.runtime.Quarkus.run(Quarkus.java:38)
	at io.quarkus.runtime.Quarkus.run(Quarkus.java:106)
	at com.github.juanmbellini.Main.main(Main.java:14)
Caused by: java.lang.reflect.InvocationTargetException
Caused by: java.lang.reflect.InvocationTargetException

	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.base/java.lang.reflect.Method.invoke(Method.java:566)
	at io.quarkus.launcher.QuarkusLauncher.launch(QuarkusLauncher.java:47)
	... 5 more
Caused by: java.lang.RuntimeException: io.quarkus.bootstrap.BootstrapException: Failed to create the application model for null
Caused by: java.lang.RuntimeException: io.quarkus.bootstrap.BootstrapException: Failed to create the application model for null

	at io.quarkus.bootstrap.IDELauncherImpl.launch(IDELauncherImpl.java:30)
	... 10 more
Caused by: io.quarkus.bootstrap.BootstrapException: Failed to create the application model for null
Caused by: io.quarkus.bootstrap.BootstrapException: Failed to create the application model for null

	at io.quarkus.bootstrap.BootstrapAppModelFactory.resolveAppModel(BootstrapAppModelFactory.java:314)
	at io.quarkus.bootstrap.app.QuarkusBootstrap.bootstrap(QuarkusBootstrap.java:157)
	at io.quarkus.bootstrap.IDELauncherImpl.launch(IDELauncherImpl.java:27)
	... 10 more
Caused by: io.quarkus.bootstrap.BootstrapException: Failed to determine the Maven artifact associated with the application /Users/jbellini/Projects/pocs/quarkus-poc/build/classes/java/main
Caused by: io.quarkus.bootstrap.BootstrapException: Failed to determine the Maven artifact associated with the application /Users/jbellini/Projects/pocs/quarkus-poc/build/classes/java/main

	at io.quarkus.bootstrap.BootstrapAppModelFactory.resolveAppModel(BootstrapAppModelFactory.java:254)
	... 12 more

Execution failed for task ':Main.main()'.
> Process 'command '/Library/Java/JavaVirtualMachines/openjdk-11.0.2.jdk/Contents/Home/bin/java'' finished with non-zero exit value 1



Expected behavior

I expect the application to start without any issue

Actual behavior
The application does not start, and the previous stacktrace is printed.

To Reproduce
Steps to reproduce the behavior:

  1. Create a project in https://code.quarkus.io/ using gradle as build tool
  2. Import the project in IntelliJ (I'm using 2020.1)
  3. Create a main class according to https://quarkus.io/guides/lifecycle#the-main-method
  4. Run the main method clicking in the "play" button next to the main method.

Configuration

 # No properties have been set

Screenshots
Captura de Pantalla 2020-07-24 a la(s) 14 28 29

Environment (please complete the following information):
Does not apply

Additional context

Have tried this using OpenJDK-11.0.2, GraalVM-20.1.0 and GraalVM-19.3.2.

@juanmbellini juanmbellini added the kind/bug Something isn't working label Jul 24, 2020
@quarkusbot quarkusbot added the area/gradle Gradle label Jul 24, 2020
@quarkusbot
Copy link

/cc @quarkusio/devtools

@aloubyansky
Copy link
Member

Is there a chance you could try current quarkus master branch? I merged a pr that should fix it a couple of hours ago.

@juanmbellini
Copy link
Author

Is master built? I have cloned the repo but it's taking too much time to build. 30 minutes already have passed and still not even reached half of the process.

@juanmbellini
Copy link
Author

@aloubyansky Ok, It has finished and it works but there are some issues:

  • Everything in the main method runs twice (in order to test, I have tried printing some stuff before calling Quarkus#run, and it was printed twice)
  • The application is taking too much time to start (from when Quarkus#run starts running till the banner is printed and the app is ready to listen for requests). This does not happen when running from command line with ./gradlew quarkusDev.

Note that my main is like this:

@QuarkusMain
public class Main {

    public static void main(final String... args) {
        System.out.println("Starting.............");
        Quarkus.run(args);
        System.out.println("After starting.............");
    }
}

@juanmbellini
Copy link
Author

It seems that after running Quarkus.run, the main method is invoked again, as "Starting............." is printed twice.

@juanmbellini
Copy link
Author

Another issue is that after stopping the app (from the IDE), there are some times in which the app does not really stops (address and port remain in use). Don't know if this has something to be with your PR though.

@aloubyansky
Copy link
Member

@juanmbellini thanks a lot for giving it a try and providing the fast feedback.
Just in case, the PR I mentioned is #10459 This is the first attempt to support IDE integration for Gradle.
I'll have a look next week into this.
FYI @glefloch

@aloubyansky
Copy link
Member

I guess the slow start relates to "connecting to the project". We'll need to investigate how we can do it more efficiently.

@glefloch
Copy link
Member

@juanmbellini thanks for these test.
How slow it is? I think @aloubyansky is right, when running from the IDE, we need to create a connection to Gradle, whereas when running from Gradle we don't need too.

@juanmbellini
Copy link
Author

@glefloch With my computer (a Macbook Pro 15" 2018, 6-core i9, with 32GiB):

  • Running from the IDE pressing the "play" button takes more or less 15~20 secs (including all the gradle tasks, as for example compileJava)

  • Instead, running using this plugin, takes about 10 secs (also including all the gradle tasks). It seems that this plugin is as running from the command line ./gradlew quarkusDev but easier as it allows you to connect the debugger easily.

  • And lastly, running from the command line ./gradlew quarkusDev takes more or less 2 secs.

@glefloch
Copy link
Member

Yes, I think we could have quite better performance, for example we are creating the model two times, with a new project connection for each one.

BTW, I have multiple sample project on my machine (including one with a CLI application) and I re run some tests today, I wasn't able to get the run method executed twice. Are you running some Gradle command before executing the main method?

@juanmbellini
Copy link
Author

Nope, just calling run from my main method, and running the application from intelliJ just pressing the "play" button as any java project with a main method.

However, some gradle tasks are run before (compileJava for instance).

But once Main.main() starts, following the execution with the debugger, I could realize that the main method is executed twice (the first time when the application starts, as it is the starting point of the execution started by intelliJ), and afterwards, it seems to start again as Quarkus seems to re-run the main method.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/gradle Gradle kind/bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants