Как добавить группу компиляции зависимостей Gradle Kotlin: 'org.seleniumhq.selenium'? - PullRequest
0 голосов
/ 17 декабря 2018

Каков синтаксис для добавить 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 голосов
/ 17 декабря 2018

См. Эту документацию: https://docs.gradle.org/current/userguide/dependency_types.html Для Зависимости модуля , синтаксис между Groovy DSL и Kotlin DSL:

Groovy:

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