fixup! Automatically the list of entry point annotations to .idea/misc.xml
diff --git a/build.gradle.kts b/build.gradle.kts index d6ad36b..573aca8 100644 --- a/build.gradle.kts +++ b/build.gradle.kts
@@ -1,7 +1,6 @@ import org.gradle.crypto.checksum.Checksum import org.gradle.plugins.ide.idea.model.IdeaModel import org.jetbrains.kotlin.gradle.targets.js.yarn.YarnLockMismatchReport -import java.io.FileNotFoundException buildscript { // a workaround for kotlin compiler classpath in kotlin project: sometimes gradle substitutes @@ -1116,15 +1115,6 @@ } } -/** - * Unused declarations annotated with annotations from this list will not be reported by the "Unused symbols" inspection. - */ -val entryPointAnnotations by extra { - listOf( - "org.jetbrains.kotlin.utils.IDEAPluginsCompatibilityAPI", - ) -} - afterEvaluate { patchIdeaMiscXml() checkExpectedGradlePropertyValues()
diff --git a/repo/gradle-build-conventions/buildsrc-compat/src/main/kotlin/patchIdeaMiscXml.kt b/repo/gradle-build-conventions/buildsrc-compat/src/main/kotlin/patchIdeaMiscXml.kt index aaabf3d..fde4172 100644 --- a/repo/gradle-build-conventions/buildsrc-compat/src/main/kotlin/patchIdeaMiscXml.kt +++ b/repo/gradle-build-conventions/buildsrc-compat/src/main/kotlin/patchIdeaMiscXml.kt
@@ -1,7 +1,5 @@ import com.sun.org.apache.xml.internal.serializer.OutputPropertiesFactory import org.gradle.api.Project -import org.gradle.kotlin.dsl.extra -import org.gradle.kotlin.dsl.provideDelegate import org.w3c.dom.Element import java.io.FileNotFoundException import javax.xml.parsers.DocumentBuilderFactory @@ -10,10 +8,51 @@ import javax.xml.transform.dom.DOMSource import javax.xml.transform.stream.StreamResult -// A workaround for IDEA-84055 +/** + * Unused declarations annotated with annotations from this list will not be reported by the "Unused symbols" inspection. + */ +private val entryPointAnnotations = listOf( + "org.jetbrains.kotlin.utils.IDEAPluginsCompatibilityAPI", +) + +/** A workaround for [IDEA-84055](https://youtrack.jetbrains.com/issue/IDEA-84055). + * This is needed because we don't store `.idea/misc.xml` in the VCS. + * + * Configures IDEA to use [entryPointAnnotations] as the list of entry points for the "Unused symbol" inspection. + * + * Suppose the `misc.xml` file already exists and has the following contents: + * ```xml + * <?xml version="1.0" encoding="UTF-8"?> + * <project version="4"> + * <component name="EntryPointsManager"> + * // Some previous data + * </component> + * <component name="OtherComponent"> + * // Some other data + * </component> + * </project> + * ``` + * + * If [entryPointAnnotations] contains items `["com.example.Annotation1", "com.example.Annotation2", "com.example.Annotation3"]`, + * the updated misc.xml content after a run of this function would look like this: + * ```xml + * <?xml version="1.0" encoding="UTF-8"?> + * <project version="4"> + * <component name="OtherComponent"> + * // Some other data + * </component> + * <component name="EntryPointsManager"> + * <list size="3"> + * <item index="0" class="java.lang.String" itemvalue="com.example.Annotation1" /> + * <item index="1" class="java.lang.String" itemvalue="com.example.Annotation2" /> + * <item index="2" class="java.lang.String" itemvalue="com.example.Annotation3" /> + * </list> + * </component> + * </project> + * ``` + */ fun Project.patchIdeaMiscXml() { - val entryPointAnnotations: List<String> by rootProject.extra - val miscXml = rootProject.rootDir.resolve(".idea/misc.xml") + val miscXml = rootDir.resolve(".idea/misc.xml") val documentBuilder = DocumentBuilderFactory.newInstance().newDocumentBuilder() val document = try { documentBuilder.parse(miscXml)