What is the best way to specify module wide *opt-i...
# gradle
e
What is the best way to specify module wide opt-in requirements in gradle scripts for it to be applied properly in Android Studio. This was broken before (https://kotlinlang.slack.com/archives/C0922A726/p1560260538220700), fixed at some point and, unfortunately, broken again now (for me). I have tried combinations of • AS [4.2.1, ArcticFox-beta03, Bumblebee-alpha02] • AGP [4.2.1, 7.0-beta03, 7.1-alpha02] • KGP [1.5.10], cant downgrade to 1.4.30 Builds fine from command line so its an issue of importing the model into IDE.
s
I use this for OptIns
Copy code
allprojects {
    repositories {
        ...
    }

    tasks {
        withType<KotlinCompile> {
            kotlinOptions {
                jvmTarget = JdkSettings.jvmTarget
                freeCompilerArgs = freeCompilerArgs + "-Xopt-in=kotlin.RequiresOptIn"
            }
        }
    }
}
Lets me use @OptIn(ExperimentalPagingApi::class) for given class and I don’t get any warnings after applying this
e
Forgot to add, right now I have:
Copy code
subprojects {
  tasks.withType<KotlinCompile<*>>().configureEach {
    kotlinOptions {
      freeCompilerArgs  = freeCompilerArgs + listOf(
        "-Xopt-in=<ANNOTATION FQCN>",
        ...
      )
    }
  }
}
@ilya.gorbunov what does it mean when there is no kotlin facet for a module inside
.idea/modules/<moduleNane>/<moduleName.iml>
Who’s responsibility is it to write the kotlin facet to that file? (Android studio OR Android gradle plugin OR gradle intellij plugin OR kotlin gradle plugin? …) 😞
i
Writing .iml files is solely the responsibility of IDEA/Android studio. I recently observed that IDEA no longer writes .imls for projects imported from Gradle. AFAIK it stores all the imported information in some place external to the project. Can it be your case?
e
Can it be your case?
Honestly, I have no idea. Way out of my depth here. I just know one of my projects where it works has the kotlin facet in the iml. But its possible that that was generated by an older IDE and if I recreate the .idea folder, I will probably face these same issues.
I recently observed that IDEA no longer writes .imls for projects imported from Gradle. AFAIK it stores all the imported information in some place external to the project.
Any idea what are my options? 😞
i
Try importing project from a clean checkout. If that doesn't help, could you create a reproducer and file it in a new issue to https://kotl.in/issue?
e
I tried importing from a clean checkout and no dice. Still working on a reproducer but not successful yet. Current reproducer doesn’t mirror my project because we have a lot of configuration using gradle features like included builds, convention plugin, custom sourcsets etc. Is there a solution for private repos as reproducers? (maybe time limited repo access given to the person who will triage the issue?)
a
Usually you just create a YouTrack issue with a private zip attachment of the reproducing project. You could even remove it if we manage to minimize the project. Another option: explicitly specify in the issue that you would need email addresses of JetBrains members who will triage and fix the bug. In that case specific people would have to be added to your project individually.
🙏 1
e
Awesome, sounds good to me. This was a blocker to creating the issue 🙏🏼
Narrowed it down to our use of gradle settings plugin / included plugin builds https://youtrack.jetbrains.com/issue/KTIJ-19297 (Not 100% sure on that 😅)