1) My builds live behind a corporate firewall and ...
# gradle
f
1) My builds live behind a corporate firewall and we set our inintscript, buildscript and regular repositories from a standard init.gradle script. This works for Gradle Groovy-DSL builds in Intellij/commandline and Gradle Kotlin-DSL on the command line. But Intellij with Gradle Kotlin-DSL fails to find the plugins from repositories defined in the init.script (as a work around I'm while testing I'm embedding the buildscript.repositories inside the build script but we don't want to do this in production as we need centralized control of the repositories for plugins). 2) Intellij is falsely reporting that it can't find the following FixCrLfFilter.CrLf static class. This code runs properly at build time. import org.apache.tools.ant.filters.FixCrLfFilter val processResources by tasks.creating(Copy::class) { // TODO: Issue with Intellij not detecting FixCrLfFilter.CrLf static class, builds fine filter<FixCrLfFilter>("eol" to FixCrLfFilter.CrLf.newInstance("lf")) } 3) Intellij is reporting in the tasks.getting that DeployTask from the com.xebialabs.xl-deploy plugin is not a subtype of Task. It is and this code does run. // TODO: Intellij false warning that DeployTask not subtype of Tase, builds file val deploy by tasks.getting(DeployTask::class) { ... }
j
I don't use an
init.script
file. Instead I have something a bit weirder but it works for my purposes. I have a
repositoryConfig.gradle.kts
file that I use like this:
Copy code
/**
 * To access this method use the following code:
 * ```kotlin
 * repositories {
 *     val repositoryConfig : (Any) -> Unit by rootProject.extra
 *     repositoryConfig(this)
 * }
 * `` `
 * @see masterRepositoryConfig
 */
fun repositoryConfig(repositoryHandler: RepositoryHandler) =
    masterRepositoryConfig(repositoryHandler, false)

/**
 * To access this method use the following code:
 * ```kotlin
 * repositories {
 *     val buildScriptRepositoryConfig : (Any) -> Unit by rootProject.extra
 *     buildScriptRepositoryConfig(this)
 * }
 * `` `
 * @see masterRepositoryConfig
 */
fun buildScriptRepositoryConfig(repositoryHandler: RepositoryHandler) =
    masterRepositoryConfig(repositoryHandler, true)

/**
 * To access this method use the following code:
 * ```kotlin
 * repositories {
 *     val publishingRepositoryConfig : (Any, Any) -> Unit by rootProject.extra
 *     publishingRepositoryConfig(version, this)
 * }
 * `` `
 * @param version The version of the project being published.
 * @param repositoryHandler The handler to be configured for publishing.
 */
fun publishingRepositoryConfig(version: String, repositoryHandler: RepositoryHandler) {
    repositoryHandler.apply {
        // Determine if the project is a SNAPSHOT on a per-project basis.
        val isSnapshot = version.contains("-SNAPSHOT")
        artifactoryLogin?.let { (artifactoryUsername, artifactoryPassword) ->
            // Only configure publishing to artifactory if the the artifactory login object is non-null.
            maven {
                credentials {
                    username = artifactoryUsername
                    password = artifactoryPassword
                }
                setUrl(if (isSnapshot) companyLibSnapshotUrl else companyLibReleaseUrl)
            }
        }
    }
}

extra["repositoryConfig"] = this::repositoryConfig
extra["publishingRepositoryConfig"] = this::publishingRepositoryConfig
extra["buildScriptRepositoryConfig"] = this::buildScriptRepositoryConfig
To use this code I do this:
Copy code
buildscript {
    applyFrom("repositoryConfig.gradle.kts")
    repositories {
        val buildScriptRepositoryConfig : (Any) -> Unit by extra
        buildScriptRepositoryConfig(this)
    }
}
Ect...
In my
buildSrc/build.gradle.kts
I do this:
Copy code
applyFrom("../repositoryConfig.gradle.kts")
repositories {
    val buildScriptRepositoryConfig : (Any) -> Unit by extra
    buildScriptRepositoryConfig(this)
}