我的gradle版本是6.0.1
安装详见另一篇文章 idea配置gradle
我是直接在idea中用git下载的,源码地址
Kotlin gradle Could not initialize class class org.jetbrains.kotlin.gradle.internal.KotlinSourceSetProviderImplKt
build.gradle文件中,定义的kotlin插件版本与idea的kotlin插件版本不一致导致,查看idea中kotlin插件版本:
修改build.gradle中版本,2个地方如下:
找到项目中的build.gradle文件,修改仓库地址
repositories {
maven {url "https://maven.aliyun.com/repository/spring"}
// mavenCentral()
// maven { url "https://repo.spring.io/libs-release" }
}
plugins {
id 'java'
}
group 'org.springframework'
version '5.1.17.BUILD-SNAPSHOT'
sourceCompatibility = 1.8
repositories {
maven { url 'http://maven.aliyun.com/nexus/content/groups/public/'}
maven { url 'https://maven.aliyun.com/repository/jcenter' }
maven { url 'https://maven.aliyun.com/repository/google' }
maven { url 'https://maven.aliyun.com/repository/central' }
maven { url 'https://maven.aliyun.com/repository/gradle-plugin' }
//mavenCentral()
}
dependencies {
testCompile group: 'junit', name: 'junit', version: '4.12'
//compile(project(":spring-context"))
//spring 开发web
compile(project(":spring-web"))
compile(project(":spring-webmvc"))
//内嵌tomcat
compile group: 'org.apache.tomcat.embed', name: 'tomcat-embed-core', version: '8.5.56'
compile group: 'org.apache.tomcat.embed', name: 'tomcat-embed-jasper', version: '8.5.56'
}
public static void main(String[] args) throws LifecycleException {
AnnotationConfigApplicationContext annotationConfigApplicationContext =
new AnnotationConfigApplicationContext(AppConfig.class);
TestService te
= (TestService) annotationConfigApplicationContext.getBean("testService");
System.out.println("sout test===================================");
System.out.println(te);
}
控制台如下,成功输出对象:
17:29:20: Executing task 'Test.main()'...
> Task :buildSrc:compileJava NO-SOURCE
> Task :buildSrc:compileGroovy UP-TO-DATE
> Task :buildSrc:processResources UP-TO-DATE
> Task :buildSrc:classes UP-TO-DATE
> Task :buildSrc:jar UP-TO-DATE
> Task :buildSrc:assemble UP-TO-DATE
> Task :buildSrc:compileTestJava NO-SOURCE
> Task :buildSrc:compileTestGroovy NO-SOURCE
> Task :buildSrc:processTestResources NO-SOURCE
> Task :buildSrc:testClasses UP-TO-DATE
> Task :buildSrc:test NO-SOURCE
> Task :buildSrc:check UP-TO-DATE
> Task :buildSrc:build UP-TO-DATE
> Configure project :
Repository https://jcenter.bintray.com/ replaced by https://maven.aliyun.com/repository/jcenter/.
> Task :spring-core:cglibRepackJar UP-TO-DATE
> Task :spring-core:objenesisRepackJar UP-TO-DATE
> Task :spring-jcl:compileKotlin UP-TO-DATE
> Task :spring-jcl:compileJava UP-TO-DATE
> Task :spring-jcl:processResources UP-TO-DATE
> Task :spring-jcl:classes UP-TO-DATE
> Task :spring-jcl:inspectClassesForKotlinIC UP-TO-DATE
> Task :spring-jcl:jar UP-TO-DATE
> Task :spring-core:compileKotlin UP-TO-DATE
> Task :spring-core:compileJava UP-TO-DATE
> Task :spring-core:processResources NO-SOURCE
> Task :spring-core:classes UP-TO-DATE
> Task :spring-core:inspectClassesForKotlinIC UP-TO-DATE
> Task :spring-core:jar UP-TO-DATE
> Task :spring-beans:compileGroovy UP-TO-DATE
> Task :spring-beans:compileKotlin UP-TO-DATE
> Task :spring-beans:compileJava NO-SOURCE
> Task :spring-beans:processResources UP-TO-DATE
> Task :spring-beans:classes UP-TO-DATE
> Task :spring-beans:inspectClassesForKotlinIC UP-TO-DATE
> Task :spring-beans:jar UP-TO-DATE
> Task :spring-aop:compileKotlin UP-TO-DATE
> Task :spring-aop:compileJava UP-TO-DATE
> Task :spring-aop:processResources UP-TO-DATE
> Task :spring-aop:classes UP-TO-DATE
> Task :spring-aop:inspectClassesForKotlinIC UP-TO-DATE
> Task :spring-aop:jar UP-TO-DATE
> Task :spring-expression:compileKotlin UP-TO-DATE
> Task :spring-expression:compileJava UP-TO-DATE
> Task :spring-expression:processResources UP-TO-DATE
> Task :spring-expression:classes UP-TO-DATE
> Task :spring-expression:inspectClassesForKotlinIC UP-TO-DATE
> Task :spring-expression:jar UP-TO-DATE
> Task :spring-instrument:compileKotlin UP-TO-DATE
> Task :spring-instrument:compileJava UP-TO-DATE
> Task :spring-instrument:processResources NO-SOURCE
> Task :spring-instrument:classes UP-TO-DATE
> Task :spring-instrument:inspectClassesForKotlinIC UP-TO-DATE
> Task :spring-instrument:jar UP-TO-DATE
> Task :spring-context:compileKotlin UP-TO-DATE
> Task :spring-context:compileJava UP-TO-DATE
> Task :spring-context:compileGroovy NO-SOURCE
> Task :spring-context:processResources UP-TO-DATE
> Task :spring-context:classes UP-TO-DATE
> Task :spring-context:inspectClassesForKotlinIC UP-TO-DATE
> Task :spring-context:jar UP-TO-DATE
> Task :spring-oxm:compileKotlin UP-TO-DATE
> Task :spring-oxm:compileJava UP-TO-DATE
> Task :spring-oxm:processResources UP-TO-DATE
> Task :spring-oxm:classes UP-TO-DATE
> Task :spring-oxm:inspectClassesForKotlinIC UP-TO-DATE
> Task :spring-oxm:jar UP-TO-DATE
> Task :spring-web:compileKotlin UP-TO-DATE
> Task :spring-web:compileJava UP-TO-DATE
> Task :spring-web:processResources UP-TO-DATE
> Task :spring-web:classes UP-TO-DATE
> Task :spring-web:inspectClassesForKotlinIC UP-TO-DATE
> Task :spring-web:jar UP-TO-DATE
> Task :spring-tx:compileKotlin UP-TO-DATE
> Task :spring-tx:compileJava UP-TO-DATE
> Task :spring-tx:processResources UP-TO-DATE
> Task :spring-tx:classes UP-TO-DATE
> Task :spring-tx:inspectClassesForKotlinIC UP-TO-DATE
> Task :spring-tx:jar UP-TO-DATE
> Task :spring-jdbc:compileKotlin UP-TO-DATE
> Task :spring-jdbc:compileJava UP-TO-DATE
> Task :spring-jdbc:processResources UP-TO-DATE
> Task :spring-jdbc:classes UP-TO-DATE
> Task :spring-jdbc:inspectClassesForKotlinIC UP-TO-DATE
> Task :spring-jdbc:jar UP-TO-DATE
> Task :spring-context-support:compileKotlin UP-TO-DATE
> Task :spring-context-support:compileJava UP-TO-DATE
> Task :spring-context-support:processResources UP-TO-DATE
> Task :spring-context-support:classes UP-TO-DATE
> Task :spring-context-support:inspectClassesForKotlinIC UP-TO-DATE
> Task :spring-context-support:jar UP-TO-DATE
> Task :spring-webmvc:compileKotlin UP-TO-DATE
> Task :spring-webmvc:compileJava UP-TO-DATE
> Task :spring-webmvc:processResources UP-TO-DATE
> Task :spring-webmvc:classes UP-TO-DATE
> Task :spring-webmvc:inspectClassesForKotlinIC UP-TO-DATE
> Task :spring-webmvc:jar UP-TO-DATE
> Task :spring-test-demo:compileKotlin
> Task :spring-test-demo:compileJava
> Task :spring-test-demo:processResources NO-SOURCE
> Task :spring-test-demo:classes
> Task :spring-test-demo:Test.main()
sout test===================================
com.clock.bone.service.TestService@701fc37a
Deprecated Gradle features were used in this build, making it incompatible with Gradle 7.0.
Use '--warning-mode all' to show the individual deprecation warnings.
See https://docs.gradle.org/6.0.1/userguide/command_line_interface.html#sec:command_line_warnings
BUILD SUCCESSFUL in 9s
68 actionable tasks: 3 executed, 65 up-to-date
17:29:30: Task execution finished 'Test.main()'.
可以看到上步中运行测试类是成功了,但是非常的慢
可以参考以下步骤将运行方式改成idea 如下:
gradle编译太慢,将gradle编译改成idea编译
步骤:
setting---->build and run using---->idea
build test using ------>idae
2、运行自己写的测试类,如果报错----》找到报错的test模块,找到test包下的java右键—》run test ,主要是为了将源码编译生成classes文件,test运行失败也没事,如果test类下有报错 方法 比如:Fligths 报错 直接将整个类注释,然后再运行test方法----》再运行自己写的test方法----》如果还有模块报错 找不到类 ----》再找到对应模块 运行它的Test ,直到不报错