danger / kotlin

⚠️ Stop saying "you forgot to …" in code review
MIT License
490 stars 48 forks source link

Can't find DangerFileScript in Kotlin Scripting #276

Open gulomov opened 5 months ago

gulomov commented 5 months ago

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.

carlosesh commented 3 months ago

I have the same issue

efemoney commented 3 months ago

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)
OptimumCode commented 2 months ago

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

ron-diesel commented 3 days ago

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

OptimumCode commented 3 days ago

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

ron-diesel commented 3 days ago

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

Hi

image
ron-diesel commented 3 days ago
image
OptimumCode commented 3 days ago

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

ron-diesel commented 3 days ago

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
OptimumCode commented 3 days ago

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

OptimumCode commented 3 days ago

But of course, the path will depend on your system

ron-diesel commented 3 days ago

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

OptimumCode commented 3 days ago

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**_
ron-diesel commented 3 days ago

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 commented 3 days ago

I figured it out, it seems the problem is this

pablobaldez commented 2 days ago

is there any workaround for this issue?

ron-diesel commented 2 days ago

@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

OptimumCode commented 2 days ago

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

pablobaldez commented 2 days ago

@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:

Screenshot 2024-09-11 at 14 01 24 Screenshot 2024-09-11 at 14 02 58
OptimumCode commented 14 hours ago

@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)