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

Build Java Gradle Applications #519

Closed
piotrzarzycki21 opened this issue Apr 15, 2019 · 8 comments
Closed

Build Java Gradle Applications #519

piotrzarzycki21 opened this issue Apr 15, 2019 · 8 comments
Assignees
Milestone

Comments

@piotrzarzycki21
Copy link
Collaborator

Sorry, I missed your earlier question. Unless we can find a reliable way to read the executable path, I think that we can hide Build & Run for Java Gradle projects.

For Project > Build, I think we should just run "$GRADLE_HOME/bin/gradle clean build" by default. You can see all of the other tasks that will be executed with this command:

$ gradle clean build
Starting a Gradle Daemon (subsequent builds will be faster)
:clean UP-TO-DATE
:compileJava
:processResources NO-SOURCE
:classes
:jar
:assemble
:compileTestJava NO-SOURCE
:processTestResources NO-SOURCE
:testClasses UP-TO-DATE
:test NO-SOURCE
:check UP-TO-DATE
:build

A more advanced solution would be to let the user configure the tasks for Gradle, similar to the Build actions for Maven.

Is there some limitation I am forgetting that prevents us from running Gradle builds like this?

Originally posted by @JoelProminic in #459 (comment)

@piotrzarzycki21
Copy link
Collaborator Author

Additional reference comment #459 (comment)

@JoelProminic
Copy link
Contributor

Note that currently (pre-2.1.0) we do not have a way to configure a Gradle installation in Moonshine, and it is not installed with Moonshine SDK Installer. We'll at least need a settings page for this if we want to include this issue in 2.2.0.

Gradle provides a wrapper that will automatically install the correct Gradle version for a project: https://docs.gradle.org/current/userguide/gradle_wrapper.html
However, this may require access to the home directory in order to save the downloaded copy of Gradle, which could trigger errors with the macOS sandbox.

@JoelProminic JoelProminic changed the title Build and Run Java Gradle Applications Build Java Gradle Applications May 8, 2019
@JoelProminic JoelProminic added this to the v2.3.0 milestone May 8, 2019
@JoelProminic
Copy link
Contributor

I added this to the 2.3.0 milestone. For this release, don't worry about a "Build & Run", just an action to run Gradle with a configured list of tasks. Note that the user can add support to run the application from Gradle with the "application" plugin - we could consider adding this to the default Java Gradle project.

Note that we had some trouble with Gradle projects in #547. If we can't resolve this soon, we may push Java Gradle support to a later release.

@JoelProminic
Copy link
Contributor

I found that we need to run a Gradle command to regenerate the classpath for the language server. I have a proposed solutions for this here: #547 (comment)

@JoelProminic
Copy link
Contributor

@rat-moonshine started adding Gradle to Moonshine SDK Installer here: Moonshine-IDE/Moonshine-SDK-Installer#9

@JoelProminic
Copy link
Contributor

@rat-moonshine added a Gradle Build > Build Actions setting (#547 (comment)). However, I found that the setting was reset when I restarted Moonshine. Please change this to "Build Tasks" for to match the Gradle terminology.

@rat-moonshine also added these Project menu actions:

  • Build - this will run /bin/gradle
  • Build & Run - this will run the same action as Build, and then also run <gradle-home/bin/gradle run
  • Clean - I need to clarify this logic

I have some concerns about this implementation:

  • Build & Run will fail if the application plugin is not configured in build.gradle
  • I could set the build task to "clean", and Project > Build would no longer be building anything
  • I could set the build task to "run", and then Build & Run would execute the application twice.

I would like to replace Build and Build & Run with an action called "Run Gradle Tasks". This will run the configured tasks from the settings. We can keep Clean for now, since this will always be available for a Gradle project.

In order to have a "running" example for new Java Gradle projects, build.gradle should be configured with "run" as the default task, and have the application plugin and main class set by default.

rat-moonshine added a commit that referenced this issue May 16, 2019
- Build & Run action removed against Gradle as Build Task should do requisite
- Set 'clean run' as default build action to Gradle
- Fix: Project name was not populating to .javaproj after settings save in Gradle project
- Fix: classpaths tag not populating after settings save for java projects
(reference #519)
@rat-moonshine
Copy link
Collaborator

rat-moonshine commented May 16, 2019

  • Gradle project menu now have "Run Gradle Tasks" instead of "Build" and "Build & Run" option (the option generally does gradle <buildAction> and close the process)
  • Default build action to Gradle project template is now "clean run" (I'm not sure if Joel ask specifically for "run" instead of "clean run" - but we have only "clean run" in present build action list)

Regarding Project > Clean option, I want to mention that the option do not run any Gradle action; But it clears one or many physical folders. In case of Gradle it clears 'build' folder, in case of Maven project it clears 'target' folder (as in case of Flex projects it generally clears 'bin-debug' and maybe other few items).

A few bug I noticed during my tests, which have rectified now; They are as follows:

  1. <option mainclass="$ProjectName"/> is populating to .javaproj after a settings' save for Gradle projects
  2. Following tags found missing to .javaproj file after a settings' save for Maven or Gradle projects - which are part of the original configuration/template:
<classpaths>
    <class path="src/main/java"/>
</classpaths>

Suggested to test with updated project templates.

@JoelProminic
Copy link
Contributor

I verified that the additional bugs you reported have been fixed. Project > Clean is now using "gradle clean". I am closing this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants