如何添加 Gradle Kotlin 依赖编译组:'org.seleniumhq.selenium'?
how to add the Gradle Kotlin dependency compile group: 'org.seleniumhq.selenium'?
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")
}
}
查看此文档: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'
}
科特林:
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.+" )
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")
}
}
查看此文档: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'
}
科特林:
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.+" )