Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
258 views
in Technique[技术] by (71.8m points)

Spring 源码包导入

  • 下图为spring源码导入后的截图

image.png

  • 为了证明是否导入成功,在spring-context子工程中添加了如下测试代码
package org.springframework;

import org.springframework.validation.AbstractErrors;

public class Test {
    public static void main(String[] args) {
        System.out.println(AbstractErrors.NESTED_PATH_SEPARATOR);
    }
}

启动结果:

10:03:41 下午: Executing task 'Test.main()'...

> Task :buildSrc:compileJava UP-TO-DATE
> Task :buildSrc:compileGroovy NO-SOURCE
> Task :buildSrc:pluginDescriptors 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:pluginUnderTestMetadata 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:validateTaskProperties UP-TO-DATE
> Task :buildSrc:check UP-TO-DATE
> Task :buildSrc:build UP-TO-DATE
> Task :wrapper

BUILD SUCCESSFUL in 2s
1 actionable task: 1 executed
> Task :buildSrc:compileJava UP-TO-DATE
> Task :buildSrc:compileGroovy NO-SOURCE
> Task :buildSrc:pluginDescriptors 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:pluginUnderTestMetadata 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:validateTaskProperties UP-TO-DATE
> Task :buildSrc:check UP-TO-DATE
> Task :buildSrc:build UP-TO-DATE
> Task :spring-expression:processResources
> Task :spring-aop:processResources
> Task :spring-core:cglibRepackJar FROM-CACHE
> Task :spring-core:objenesisRepackJar FROM-CACHE
> Task :spring-beans:processResources
> Task :spring-core:processResources NO-SOURCE
> Task :spring-context:processResources
> Task :spring-instrument:compileJava FROM-CACHE
> Task :spring-instrument:processResources NO-SOURCE
> Task :spring-instrument:classes UP-TO-DATE
> Task :spring-instrument:jar
> Task :spring-jcl:compileJava FROM-CACHE
> Task :spring-jcl:processResources
> Task :spring-jcl:classes
> Task :spring-jcl:jar
> Task :kotlin-coroutines:compileKotlin FROM-CACHE
> Task :kotlin-coroutines:compileJava NO-SOURCE
> Task :kotlin-coroutines:processResources NO-SOURCE
> Task :kotlin-coroutines:classes UP-TO-DATE
> Task :kotlin-coroutines:inspectClassesForKotlinIC
> Task :kotlin-coroutines:jar
> Task :spring-core:compileKotlin FROM-CACHE
> Task :spring-core:compileJava FROM-CACHE
> Task :spring-core:classes UP-TO-DATE
> Task :spring-core:inspectClassesForKotlinIC
> Task :spring-core:jar
> Task :spring-expression:compileKotlin FROM-CACHE
> Task :spring-expression:compileJava FROM-CACHE
> Task :spring-expression:classes
> Task :spring-expression:inspectClassesForKotlinIC
> Task :spring-expression:jar
> Task :spring-beans:compileGroovy
> Task :spring-beans:compileGroovy FROM-CACHE
> Task :spring-beans:compileKotlin
> Task :spring-beans:compileJava NO-SOURCE
> Task :spring-beans:classes
> Task :spring-beans:inspectClassesForKotlinIC
> Task :spring-beans:jar
> Task :spring-aop:compileJava
> Task :spring-aop:compileJava FROM-CACHE
> Task :spring-aop:classes
> Task :spring-aop:jar
> Task :spring-context:compileKotlin
> Task :spring-context:compileJava
> Task :spring-context:compileGroovy NO-SOURCE
> Task :spring-context:classes

> Task :spring-context:Test.main()
.

BUILD SUCCESSFUL in 2m 0s
31 actionable tasks: 20 executed, 11 from cache
10:05:44 下午: Task execution finished 'Test.main()'.

输出了内容. 因此认为spring 源码环境搭建成功,但是在创建子项目后创建测试用例

public class Demo {
    public static void main(String[] args) {
        BeanFactory beanFactory = new ClassPathXmlApplicationContext("META-INF/dependency.xml");
        UserEntity bean = beanFactory.getBean(UserEntity.class);
        System.out.println(bean);
    }
}

image.png
此时包找不到了.
但是我在 5.1.15.build-snapshot 版本中可以正常使用

gradle 配置截图
image.png

build.gradle

plugins {
    id 'java'
}

group 'org.springframework'
version '5.2.3.RELEASE'

repositories {
    mavenCentral()
}

dependencies {
    compile(project(":spring-beans"))
    compile(project(":spring-core"))

    testCompile group: 'junit', name: 'junit', version: '4.12'
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
rootProject.name = "spring"
rootProject.children.each {project ->
    project.buildFileName = "${project.name}.gradle"
}

通过观察spring-framework 的settings.gradle文件发现需要spring作为项目开头 , 因此修改项目名称即可完成包导入


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...