kotlin icon indicating copy to clipboard operation
kotlin copied to clipboard

Can't find DangerFileScript in Kotlin Scripting

Open gulomov opened this issue 10 months ago • 20 comments

Hello people, I am trying to activate the autocomplete, and after adding Script template classes and Script templates classpath Screenshot 2024-04-12 at 13 19 34

I want to activate DangerFileScript but don't see it in Kotlin Scripting.

Screenshot 2024-04-12 at 13 25 00

I see this cause of errors (Unresolved reference: danger) in my Dangerfile.df.kts

`import systems.danger.kotlin.*

danger(args) {

onGitHub {

    // Big PR Check
    if ((pullRequest.additions ?: 0) - (pullRequest.deletions ?: 0) > 300) {
        warn("Big PR, try to keep changes smaller if you can")
    }

    // Work in progress check
    if (pullRequest.title.contains("WIP", false)) {
        warn("PR is classed as Work in Progress")
    }
}

}`

Am I missing something or doing something wrong? Thank you very much.

gulomov avatar Apr 12 '24 11:04 gulomov

I have the same issue

carlosesh avatar May 28 '24 17:05 carlosesh

Same issue, you can see what is wrong from the IDE logs

Caused by: kotlin.script.experimental.jvm.util.ClasspathExtractionException: Unable to get script compilation classpath from context, please specify explicit classpath via "kotlin.script.classpath" property
	at kotlin.script.experimental.jvm.util.JvmClasspathUtilKt.scriptCompilationClasspathFromContext(jvmClasspathUtil.kt:345)
	at kotlin.script.experimental.jvm.JvmScriptCompilationKt.dependenciesFromClassloader(jvmScriptCompilation.kt:57)
	at kotlin.script.experimental.jvm.JvmScriptCompilationKt.dependenciesFromClassloader$default(jvmScriptCompilation.kt:50)
	at kotlin.script.experimental.jvm.JvmScriptCompilationKt.dependenciesFromClassContext(jvmScriptCompilation.kt:39)
	at kotlin.script.experimental.jvm.JvmScriptCompilationKt.dependenciesFromClassContext$default(jvmScriptCompilation.kt:36)
	at systems.danger.kts.DangerFileScriptDefinition$1$1.invoke(DangerFileScriptDefinition.kt:37)
	at systems.danger.kts.DangerFileScriptDefinition$1$1.invoke(DangerFileScriptDefinition.kt:36)
	at kotlin.script.experimental.util.PropertiesCollection$Builder.invoke(propertiesCollection.kt:282)
	at systems.danger.kts.DangerFileScriptDefinition$1.invoke(DangerFileScriptDefinition.kt:36)
	at systems.danger.kts.DangerFileScriptDefinition$1.invoke(DangerFileScriptDefinition.kt:34)
	at kotlin.script.experimental.api.ScriptCompilationConfiguration.<init>(scriptCompilation.kt:23)
	at kotlin.script.experimental.api.ScriptCompilationConfiguration.<init>(scriptCompilation.kt:25)
	at systems.danger.kts.DangerFileScriptDefinition.<init>(DangerFileScriptDefinition.kt:33)
	at systems.danger.kts.DangerFileScriptDefinition.<clinit>(DangerFileScriptDefinition.kt)

efemoney avatar Jun 07 '24 10:06 efemoney

Hi, I had the same issue. Here is how I fixed that:

  1. Do all the instructions from the main README file.
  2. Go to Main Menu -> Help -> Edit Custom Properties...
  3. Add the following line to the file (for macOs the path would probably be different but unfortunately I don't have macOs to provide an example. Probably, something like this /opt/homebrew/Cellar/danger-kotlin/1.3.0/lib/danger/libs based on the screenshot in the issue description):
    kotlin.script.classpath=/usr/local/lib/danger/libs
    
  4. Restart your IDE

After that, you should see the DangerFileScript in Kotlin scripting menu. image

Hope it will help someone. Also, the instructions in the main README should probably be updated. I think many people have the same issue and might not use this project because of that

OptimumCode avatar Jun 22 '24 11:06 OptimumCode

Hi, I had the same issue. Here is how I fixed that:

  1. Do all the instructions from the main README file.
  2. Go to Main Menu -> Help -> Edit Custom Properties...
  3. Add the following line to the file (for macOs the path would probably be different but unfortunately I don't have macOs to provide an example. Probably, something like this /opt/homebrew/Cellar/danger-kotlin/1.3.0/lib/danger/libs based on the screenshot in the issue description):
    kotlin.script.classpath=/usr/local/lib/danger/libs
    
  4. Restart your IDE

After that, you should see the DangerFileScript in Kotlin scripting menu. image

Hope it will help someone. Also, the instructions in the main README should probably be updated. I think many people have the same issue and might not use this project because of that

it didn't help, I suspect because I can't follow the first part of the instructions in the readme, since even the main menu of the new versions of Android Studio doesn't have the appropriate fields

ron-diesel avatar Sep 10 '24 10:09 ron-diesel

Hi, @ron-diesel. What do you see in kotlin section?

OptimumCode avatar Sep 10 '24 10:09 OptimumCode

Hi, @ron-diesel. What do you see in kotlin section?

Hi image

ron-diesel avatar Sep 10 '24 10:09 ron-diesel

image

ron-diesel avatar Sep 10 '24 10:09 ron-diesel

Please, take a look at issue description. The screenshot from there should help you

OptimumCode avatar Sep 10 '24 10:09 OptimumCode

Please, take a look at issue description. The screenshot from there should help you

So i need to add such setting as issue author? image

ron-diesel avatar Sep 10 '24 10:09 ron-diesel

Yes, as far as I remember, I did the same. Can share with you my settings once I have access to my laptop

OptimumCode avatar Sep 10 '24 10:09 OptimumCode

But of course, the path will depend on your system

OptimumCode avatar Sep 10 '24 10:09 OptimumCode

IDE does not allow to apply this setting. Which version of AS do you use?

ron-diesel avatar Sep 10 '24 10:09 ron-diesel

Originally, I did it in IntelliJ IDEA. But I just tried it in AS Koala and everything worked (after the AS restart). I did not have any problems with applying those settings.

Android Studio details

Android Studio Koala Feature Drop | 2024.1.2 Build #AI-241.18034.62.2412.12266719, built on August 23, 2024

OptimumCode avatar Sep 10 '24 16:09 OptimumCode

Originally, I did it in IntelliJ IDEA. But I just tried it in AS Koala and everything worked (after the AS restart). I did not have any problems with applying those settings.

Android Studio details Android Studio Koala Feature Drop | 2024.1.2 Build #AI-241.18034.62.2412.12266719, built on August 23, 2024

Then please tell me where your path leads and what's in the libs folder. In my case there is no libs folder, there is only /opt/homebrew/opt/danger-kotlin/lib/danger/danger-kotlin.jar

ron-diesel avatar Sep 10 '24 18:09 ron-diesel

I figured it out, it seems the problem is this

ron-diesel avatar Sep 10 '24 19:09 ron-diesel

is there any workaround for this issue?

pablobaldez avatar Sep 11 '24 09:09 pablobaldez

@pablobaldez I created an empty Kotlin project, added this

dependencies {
    implementation "org.jetbrains.kotlin:kotlin-script-runtime:1.8.22"
    implementation files('/opt/homebrew/opt/danger-kotlin/lib/danger/danger-kotlin.jar')
}

to build.gradle, put the danger file into the src/main/kotlin and edited it with syntax highlighting, then manually transferred the finished script to the main project. There is also an option to wait until this is fixed in Android Studio

ron-diesel avatar Sep 11 '24 10:09 ron-diesel

Hi, @pablobaldez. Maybe you can try IntelliJ IDEA instead of Android Studio (if you are okay with switching between IDEs of course). I did not observe any issues with IDEA

OptimumCode avatar Sep 11 '24 11:09 OptimumCode

@OptimumCode I tried the community IntelliJ but then another problem appeared. I made the DangerFileScript appears in the Kotlin Scritp list (only after changing idea.properties file) But the references still not found in the script file.

obs:

  • Restarting the IDE didn't work
  • I'm using mac ARM
  • This is my idea.properties kotlin.script.classpath=/opt/homebrew/opt/danger-kotlin/lib/danger
Screenshot 2024-09-11 at 14 01 24 Screenshot 2024-09-11 at 14 02 58

pablobaldez avatar Sep 11 '24 12:09 pablobaldez

@pablobaldez Unfortunately, I am using Linux not a Mac so I cannot even try to reproduce the problem. However, you probably can find some useful information about the problem's cause in IDE logs. If you are using ToolBox you can click Show log files image

and look for idea.log file. Otherwise, you need to go to Menu > Help > Show logs in IDE itself (more here)

OptimumCode avatar Sep 13 '24 13:09 OptimumCode