jbang-idea icon indicating copy to clipboard operation
jbang-idea copied to clipboard

Sync dependencies between build.gradle and JBang script

Open linux-china opened this issue 3 years ago • 10 comments
trafficstars

In edit mode, some developers add dependencies in build.gradle for code completion etc. Finally they should copy dependencies to JBang script with //DEPS directive. Introduce a shortcut to sync dependencies from Gradle to JBang script with //DEPS filled.

Reverse flow should be considered too. Introduce intention action for //DEPS and add dependency to build.gradle. With Github Copilot, and it's easy to add dependency in script.

linux-china avatar Dec 24 '21 06:12 linux-china

this is not something that should be done by jbang idea plugin imo - at least not in its final form. users should not be encouraged to edit build.gradle when using jbang - build.gradle is to be treated as purely temporary intermediate format as jbang edit will regenerate build.gradle anyway.

we have prs/issues that suggest to add deps.txt as a more centralized location if that is a problem.

maxandersen avatar Dec 26 '21 00:12 maxandersen

@maxandersen I have implemented this feature in 0.3.0 version. Sync Dependencies Action: right click script file and sync dependencies between JBang and Gradle. //DEPS to implementation or implementation to //DEPS .

Screen Shot 2021-12-25 at 6 41 07 PM

linux-china avatar Dec 26 '21 02:12 linux-china

I really don't think this is right. Sure it's a nice feature but we should NOT assume build.gradle even exist.

maxandersen avatar Dec 26 '21 18:12 maxandersen

If build.gradle not found, and Sync JBang DEPS will not available.

For most developers, two ways to open JBang with IDEA:

  • idea -e Hello.java: Light mode, and JBang plugin will not be loaded by IDEA
  • jbang edit --open=idea HelloWorld.java : build.gradle available for plugin
  • idea .: open current directory as idea project

I think we should have a good practice to code JBang script with IDEA, and developers can enjoy features supplied by the plugin.

linux-china avatar Dec 26 '21 19:12 linux-china

Sync DEPS as IDEA module's libraries when using idea . to open JBang project without build.gradle

The new logic as following:

  • if build.gradle detected, sync DEPS between JBang and Gradle
  • if build.gradle not detected, sync DEPS as IDEA module's libraries

linux-china avatar Dec 27 '21 00:12 linux-china

I'm concerned whatever this sync does it gets out of sync (no pun intended :) with how jbang edit works; especially upcoming jbang edit . (see https://github.com/jbangdev/jbang/pull/1042).

p.s. could we move to use pull-request before pushing to main - would be great to learn a bit more on how idea plugins evolves and pull-requests lets one see that vs raw push to main - even if pushed more or less directly.

maxandersen avatar Dec 27 '21 07:12 maxandersen

Gradle project models for dependencies sync :

  • JBang script as standalone module: good for mutli-module project

settings.gradle

include 'app'
include 'jbang1'
  • JBang script as sourceset: single-module project
sourceSets {
  hello {
    java {
      srcDirs = ["src/hello/java"]
    }
  }

linux-china avatar Feb 09 '22 21:02 linux-china

I really do not think the same action should be used to sync from build.gralde to java file and the java file to idea library. It's not symmetrical actions.

maxandersen avatar Feb 09 '22 23:02 maxandersen

I agree, too complicated for developers. What's your suggestion? just to keep DEPS to idea module in IDE?

If developers want to generate build.gradle, and it's easy with following command.

jbang edit --open=[editor] helloworld.java

I think build.gradle to DEPS not necessary, and I can remove these code.

linux-china avatar Feb 09 '22 23:02 linux-china

the feature is interesting (similar could be done for maven) but should be in separate actions. so if interested in tuning that keep it in a separate action "Sync JBang with Gradle" or similar.

Also perfectly fine dropping it for now as we have no tests and there are so many edge cases I fear its going to be a nightmare to maintain.

maxandersen avatar Feb 10 '22 08:02 maxandersen