如何添加Gradle Kotlin依赖项编译组:“ org.seleniumhq.selenium”?

时间:2018-12-17 13:03:11

标签: selenium gradle kotlin dependencies gradle-kotlin-dsl

add Selenium用作使用Gradle Kotlin DSL的依赖项的语法是什么?

错误:

thufir@dur:~/NetBeansProjects/HelloKotlinWorld$ 
thufir@dur:~/NetBeansProjects/HelloKotlinWorld$ gradle clean

> Configure project :
e: /home/thufir/NetBeansProjects/HelloKotlinWorld/build.gradle.kts:18:18: Expecting an element
e: /home/thufir/NetBeansProjects/HelloKotlinWorld/build.gradle.kts:18:20: Unexpected tokens (use ';' to separate expressions on the same line)
e: /home/thufir/NetBeansProjects/HelloKotlinWorld/build.gradle.kts:18:5: Unresolved reference. None of the following candidates is applicable because of receiver type mismatch: 
public val NamedDomainObjectContainer<Configuration>.compile: NamedDomainObjectProvider<Configuration> defined in org.gradle.kotlin.dsl

FAILURE: Build failed with an exception.

* Where:
Build file '/home/thufir/NetBeansProjects/HelloKotlinWorld/build.gradle.kts' line: 18

* What went wrong:
Script compilation errors:

  Line 18:     compile group: 'org.seleniumhq.selenium', name: 'selenium-java', version: '3.+'
                            ^ Expecting an element

  Line 18:     compile group: 'org.seleniumhq.selenium', name: 'selenium-java', version: '3.+'
                              ^ Unexpected tokens (use ';' to separate expressions on the same line)

  Line 18:     compile group: 'org.seleniumhq.selenium', name: 'selenium-java', version: '3.+'
               ^ Unresolved reference. None of the following candidates is applicable because of receiver type mismatch: 
                   public val NamedDomainObjectContainer<Configuration>.compile: NamedDomainObjectProvider<Configuration> defined in org.gradle.kotlin.dsl

3 errors

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

* Get more help at https://help.gradle.org

Deprecated Gradle features were used in this build, making it incompatible with Gradle 6.0.
Use '--warning-mode all' to show the individual deprecation warnings.
See https://docs.gradle.org/5.0/userguide/command_line_interface.html#sec:command_line_warnings

BUILD FAILED in 2s
thufir@dur:~/NetBeansProjects/HelloKotlinWorld$ 

构建文件:

import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar

plugins {
    kotlin("jvm") version "1.3.11"
    id("com.github.johnrengelman.shadow") version "2.0.4"
}

group = "xxx.yyy"
version = "1.0-SNAPSHOT"

repositories {
    mavenCentral()
}

dependencies {
    implementation(kotlin("stdlib-jdk8"))
    compile group: 'org.seleniumhq.selenium', name: 'selenium-java', version: '3.+'
}

tasks.withType<KotlinCompile> {
    kotlinOptions.jvmTarget = "1.8"
}

tasks.withType<ShadowJar> {

    baseName = "app"
    classifier = "inajar"
    version = "9"


    manifest.attributes.apply {
        put("Implementation-Title", "Gradle Jar File Example")
        //put("Implementation-Version" version)
        put("Main-Class", "HelloKotlinWorld.App")
    }

}

1 个答案:

答案 0 :(得分:3)

请参阅此文档:https://docs.gradle.org/current/userguide/dependency_types.html 对于模块依赖性,Groovy DSL和Kotlin DSL的语法不同:

时髦:

dependencies {
    runtime group: 'org.springframework', name: 'spring-core', version: '2.5'
}

科特琳:

dependencies {
    runtime(group = "org.springframework", name = "spring-core", version = "2.5")

请注意,您还需要将单引号替换为双引号(请参见https://guides.gradle.org/migrating-build-logic-from-groovy-to-kotlin/#prepare_your_groovy_scripts

您应该写

compile  (group= "org.seleniumhq.selenium", name = "selenium-java", version =  "3.+" )