扫一扫下方二维码,关注本站官方公众号
获取永久解锁本站全部文章的验证码
还能不定期领现金红包

idea构建 spring5.x源码-Kotlin gradle Could not initialize class class org.jetbrains.kotlin.gradle.intern-Go语言中文社区

idea构建 spring5.x源码-Kotlin gradle Could not initialize class class org.jetbrains.kotlin.gradle.intern



spring 源码后来改成了用gradle构建。

一、你必须先安装gradle

我的gradle版本是6.0.1
安装详见另一篇文章
idea配置gradle

二、下载源码

我是直接在idea中用git下载的,源码地址

三、build.gradle文件报错

在这里插入图片描述
不用管,这个没影响

四、build报错

Kotlin gradle Could not initialize class class org.jetbrains.kotlin.gradle.internal.KotlinSourceSetProviderImplKt

build.gradle文件中,定义的kotlin插件版本与idea的kotlin插件版本不一致导致,查看idea中kotlin插件版本:
在这里插入图片描述
修改build.gradle中版本,2个地方如下:
在这里插入图片描述
在这里插入图片描述

五、build慢

找到项目中的build.gradle文件,修改仓库地址

repositories {
		maven {url "https://maven.aliyun.com/repository/spring"}
		// mavenCentral()
		// maven { url "https://repo.spring.io/libs-release" }
	}

六、创建自己的模块

在spring 源码中创建一个自己的模块:

在这里插入图片描述

build.gradle如下

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'
}

运行main方法:

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()'.

6.1、在源码中,用gradle运行测试类太慢

可以看到上步中运行测试类是成功了,但是非常的慢
可以参考以下步骤将运行方式改成idea 如下:
gradle编译太慢,将gradle编译改成idea编译
步骤:

1、setting

setting---->build and run using---->idea
build test using ------>idae
在这里插入图片描述

2、通过运行测试类 编译生成class文件

2、运行自己写的测试类,如果报错----》找到报错的test模块,找到test包下的java右键—》run test ,主要是为了将源码编译生成classes文件,test运行失败也没事,如果test类下有报错 方法 比如:Fligths 报错 直接将整个类注释,然后再运行test方法----》再运行自己写的test方法----》如果还有模块报错 找不到类 ----》再找到对应模块 运行它的Test ,直到不报错

在这里插入图片描述

七、更新–download jar from https://repo.spring.io 401

在这里插入图片描述
修改项目中,build.gradle文 件:,
添加maven { url "http://repo.springsource.org/plugins-release" }

buildscript {
	repositories {

		maven { url "http://repo.springsource.org/plugins-release" }
		maven { url 'http://maven.aliyun.com/nexus/content/groups/public/' }
		maven { url "https://repo.spring.io/plugins-release" }
		//maven { url 'https://mvnrepository.com/' }
	}
	dependencies {
		classpath("io.spring.gradle:propdeps-plugin:0.0.9.RELEASE")
		classpath("org.asciidoctor:asciidoctorj-pdf:1.5.0-alpha.16")
	}
}
版权声明1:本文来源CSDN,感谢博主原创文章,遵循 CC 4.0 by-sa 版权协议,转载请附上原文出处链接和本声明。
原文链接:https://blog.csdn.net/lh87270202/article/details/106874355
站方申明:本站部分内容来自社区用户分享,若涉及侵权,请联系站方删除。
  • 发表于 2021-12-12 00:50
  • 阅读 ( 924 )

0 条评论

请先 登录 后评论

官方社群