selenium - 如何添加Gradle Kotlin依赖编译组: 'org.seleniumhq.selenium' ?

标签 selenium gradle kotlin dependencies gradle-kotlin-dsl

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

错误:

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")
    }

}

最佳答案

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

常规:

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

Kotlin :

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.+" )

关于selenium - 如何添加Gradle Kotlin依赖编译组: 'org.seleniumhq.selenium' ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53815828/

相关文章:

java - Selenium 网络抓取信息到列表中

java - Chromedriver 在 selenium web 驱动程序中打开一个空白页面而不是目标网站

Selenium 网络驱动程序 : cssselector

android - 更新到 Android Studio 2.3 Canary 3 后 Gradle 构建失败

gradle - 由于delta_set中没有默认值,如何解决dbdeploy中的SchemaVersionTrackingException?

android - 没有可用于离线模式的 androidx.databinding :databinding-compiler:3. 4.2 的缓存版本

android-studio - 在 Kotlin 中编写 x == 1 && y == 1 && z == 1 的更简单方法?

java - 文本中存在 ' 和/时的 Xpath 语法

hibernate - 为什么带有@EmbeddedId的实体不能在对应的@Embeddable类中使用LocalDateTime?

kotlin - 带有 JUnit5 的 Kotlin 1.4 中的非静态 @RegisterExtension 字段