Tag: gradle

Kotlin应用程序与Gradle应用程序插件

我正在尝试使用kotlin , gradle和gradle application插件来创建一个简单的HelloWorld应用application 。 当我用下面的设置运行它时,出现以下错误: Error: Main method is not static in class com.petarkolaric.helloworld.Main, please define the main method as: public static void main(String[] args) 我的build.gradle : group ‘helloworld’ version ‘1.0-SNAPSHOT’ buildscript { ext.kotlin_version = ‘1.2.0’ repositories { mavenCentral() } dependencies { classpath “org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version” } } apply plugin: ‘kotlin’ apply plugin: ‘application’ mainClassName = […]

IntelliJ IDEA无法findorg.jetbrains.kotlin:kotlin-gradle-plugins

尝试在IntelliJ IDEA中打开Corda演示,并在尝试导入Gradle设置时收到此错误 错误:无法findorg.jetbrains.kotlin:kotlin-gradle-plugins:1.1.4。 在以下位置搜索:file:/ C:/Users/Default/.m2/repository/org/jetbrains/kotlin/kotlin-gradle-plugins/1.1.4/kotlin-gradle-plugins-1.1.4.pom file: /C:/Users/Default/.m2/repository/org/jetbrains/kotlin/kotlin-gradle-plugins/1.1.4/kotlin-gradle-plugins-1.1.4.jar https://repo1.maven.org/ maven2 / org / jetbrains / kotlin / kotlin-gradle-plugins / 1.1.4 / kotlin-gradle-plugins-1.1.4.pom https://repo1.maven.org/maven2/org/jetbrains/kotlin/kotlin-gradle -plugins / 1.1.4 / kotlin-gradle-plugins-1.1.4.jar https://jcenter.bintray.com/org/jetbrains/kotlin/kotlin-gradle-plugins/1.1.4/kotlin-gradle-plugins- 1.1.4.pom https://jcenter.bintray.com/org/jetbrains/kotlin/kotlin-gradle-plugins/1.1.4/kotlin-gradle-plugins-1.1.4.jar需求方:项目: 我找不到任何文件来建议如何解决这个问题,任何想法?

Kotlin脚本为Gradle配置 – 传递参数不使用扩展名

我在项目中使用Kotlin脚本作为Gradle模块的配置。 我有一个自定义部署插件,在运行时为每个服务器实例配置。 我使用扩展从脚本传递参数插件,因为它是写在gradle文档 。 build.gradle.kts : apply { plugin(DeployPlugin::class.java) } extensions.add(“settingsExtension”, {s: Server -> getSettings(s)}) fun getSettings(cfg: Server) = DeploySettings( //configure it with respect to cfg ) DeployPlugin.kt : val settingsExtension = project.extensions.getByName(“settingsExtension”) as ((Server) -> DeploySettings) val settings = settingsExtension.invoke(currentServer) 我不喜欢这种配置方式是我在每个模块配置添加扩展是样板代码。 除非我执行任务,否则我不知道它是否正确。 有没有其他方法可以将getSettings函数传递给插件代码? 谢谢。

Gradle 3.0.0-alpha1与kotlin-android插件1.1.2-3不兼容?

我安装Android Studio 3.0 Canary 1并使用kotlin创建新项目。 并得到这个错误: 错误:无法find方法’com.android.build.gradle.internal.variant.BaseVariantData.getOutputs()Ljava / util / List;’。 这种意外错误的可能原因包括: Gradle的依赖关系缓存可能已损坏(有时发生在网络连接超时之后)。重新下载依赖项并同步项目(需要网络) Gradle构建过程(守护进程)的状态可能已损坏。 停止所有的Gradle守护进程可能会解决这个问题。 停止Gradle构建过程(需要重新启动) 您的项目可能使用与项目中的其他插件或项目请求的Gradle版本不兼容的第三方插件。 在损坏的Gradle进程的情况下,您也可以尝试关闭IDE,然后杀死所有的Java进程。 如果我从build.gradle中删除kotlin-android插件,那么它将成功构建。 构建gradle: buildscript { ext.kotlin_version = ‘1.1.2-3’ repositories { maven { url ‘https://maven.google.com’ } jcenter() } dependencies { classpath ‘com.android.tools.build:gradle:3.0.0-alpha1’ classpath “org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version” // NOTE: Do not place your application dependencies here; they belong // in the individual […]

将Kotlin添加到现有Java项目会打破Android Studio gradle消息错误

我是Gradle和Android的新手,但是因为我已经把Kotlin添加到了我的项目中,所以我在Android Studio中遇到一个错误,我需要通过Gradle控制台,默认情况下不会给我任何好的堆栈跟踪或路径。 在现在出现错误的Gradle消息视图中,我只能得到 错误:执行任务’:app:kaptDebugKotlin’失败。 内部编译器错误。 查看日志了解更多详情 这是预期的function,因为它似乎在jetbrains示例项目中工作正常。 我的项目Gradle文件 buildscript { ext.kotlin_version = ‘1.1.4-2’ repositories { jcenter() } dependencies { classpath ‘com.android.tools.build:gradle:2.3.3’ classpath “org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version” // NOTE: Do not place your application dependencies here; they belong // in the individual module build.gradle files } } allprojects { repositories { jcenter() } } task clean(type: Delete) { delete […]

如何使用Gradle和Kotlin创建单独的测试?

我正在使用包含unit testing的Gradle开发Kotlin项目。 我想添加一些集成测试(或function测试,从来没有理解两者之间的差异),但我希望能够独立运行它们。 理想情况下,测试的来源在不同的文件夹中。 我正在使用Gradle 4.5,我的build.gradle文件看起来像这样: buildscript { ext.kotlin_version = ‘1.2.21’ repositories { mavenCentral() } dependencies { classpath “org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version” } } apply plugin: ‘kotlin’ apply plugin: ‘application’ mainClassName = ‘xyz.bobdudan.myproject.AppKt’ repositories { maven { url “http://maven.stardog.com” } mavenCentral() } dependencies { compile “org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version” testCompile ‘io.kotlintest:kotlintest:2.0.7’ } 我已经尝试了这里描述的方法为java,但它不起作用:任务也运行unit testing,但他们不能被发现,集成测试根本不执行。 我能做什么 ? 编辑: 下面是使用@ lance-java解决方案的gradle clean integTest的结果: […]

测试包不读取主包中定义的Kotlin类

我似乎无法访问Android Studio项目中我的Kotlin模块中的测试包中的主要类。 请注意,下面显示的所有代码位于导入到Android应用程序中的Kotlin JVM模块中。 这是我的src/main/java代码: import com.google.gson.annotations.SerializedName data class Customer(val password1: String, val password2: String, @SerializedName(“last_name”) val lastName: String, @SerializedName(“first_name”) val firstName: String, val email: String) 我的测试代码在src/test/java : class CreateUser { @Test fun createRandomUser() { val random = Random() val randomNumber = random.nextInt(10000000) val customer = Customer(“password”, “password”, “lastName”, “firstName”, “ted$randomNumber@gmail.com”) } } 我的build.gradle代码如下所示: buildscript […]

无法find参数的方法springBoot() – 使用Kotlin的Spring Boot

我尝试用Kotlin创建第一个Spring Boot应用程序。 所以,也许我做了一些明显的错误或类似的东西。 我的gradle.build是: buildscript { ext.kotlin_version = ‘1.0.5-2’ ext.spring_boot_version = ‘1.4.2.RELEASE’ repositories { jcenter() } dependencies { classpath “org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version” classpath “org.springframework.boot:spring-boot-gradle-plugin:$spring_boot_version” } } apply plugin: ‘idea’ apply plugin: ‘kotlin’ apply plugin: ‘application’ jar { baseName = ‘rest-voter’ version = ‘0.1.0’ } springBoot { mainClass = ‘ru.hixon.Application’ } repositories { jcenter() } dependencies { compile […]

如何覆盖gradle kotlin-dsl中的任务

在Groovy中,我覆盖了这样一个任务: task jar(overwrite: true) { … } 我如何用Kotlin-dsl来做到这一点? 我知道我可以创建一个这样的任务: tasks { val jar by creating { … } } 但是我无法find将其声明为覆盖的等效方法,这会导致错误

将Kotlin下载到Android Studio时出现与证书相关的错误

我正在努力实现的是: 所以我试图把Kotlin安装到Android Studio中。 我相信它已经安装了,但是当Gradle尝试构建项目时,我得到一个错误。 这是我的错误进入的地方。 问题: 当Gradle尝试构建项目时,它给了我这个错误: 错误:原因:找不到要求的目标的有效证书路径 这是我的build.gradle项目文件: buildscript { ext.kotlin_version = ‘1.1.2-4’ repositories { jcenter() } dependencies { classpath ‘com.android.tools.build:gradle:2.3.2’ classpath “org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version” // NOTE: Do not place your application dependencies here; they belong // in the individual module build.gradle files } } allprojects { repositories { jcenter() } } task clean(type: Delete) { […]