Kotlin-dsl-samples: Unable to activate pre-emptive authentication with Kotlin DSL

Created on 14 Sep 2018  路  2Comments  路  Source: gradle/kotlin-dsl-samples

In https://docs.gradle.org/2.7/release-notes.html#support-for-preemptive-http-authentication it demonstrates that you can tell Gradle to preemptively sent BasicAuth headers.

Expected Behavior

I should be able to configure the Authentication method

repositories {
  maven {
    url = uri("https://my.mavenrepo.com/artifactory/mvn-main")
    authentication {
      basic(BasicAuthentication) // enable preemptive authentication (won't compile)
    }

    credentials {
      username = mavenUser
      password = password
    }
  }

}

Current Behavior

It isn't clear how to enable the BasicAuth preemptive auth mechanism.

Context

I'm trying to enable auth in the pluginManagement in my settings.gradle.kts, and am seeing it misbehave (likely will be opening another issue in that regard)

Steps to Reproduce (for bugs)

Code sample is above

Your Environment

I'm using Gradle 4.10.1, on OSX with the included Gradle Kotlin DSL

question

Most helpful comment

The nightly build of the Gradle user manual now has samples demonstrating this with the Kotlin DSL.
See https://docs.gradle.org/nightly/userguide/repository_types.html#sub:authentication_schemes

Here's your sample translated:

repositories {
    maven {
        url = uri("https://my.mavenrepo.com/artifactory/mvn-main")
        authentication {
            create<BasicAuthentication>("basic")
        }
        credentials {
            username = mavenUser
            password = password
        }
    }
}

Closing as answered

All 2 comments

Kotlin is static typed.
Means you have to use the class there:

basic(BasicAuthentication::class.java) {
}

(Maybe just BasicAuthentication::class works too).

Update

Maybe I'm wrong with the solution above
Just checked the docu again.
Checkout the AuthenticationContainer.
Seems it should be:

authentication {
  create(basic, BasicAuthentication::class.java)
}

The nightly build of the Gradle user manual now has samples demonstrating this with the Kotlin DSL.
See https://docs.gradle.org/nightly/userguide/repository_types.html#sub:authentication_schemes

Here's your sample translated:

repositories {
    maven {
        url = uri("https://my.mavenrepo.com/artifactory/mvn-main")
        authentication {
            create<BasicAuthentication>("basic")
        }
        credentials {
            username = mavenUser
            password = password
        }
    }
}

Closing as answered

Was this page helpful?
0 / 5 - 0 ratings