阅读spring源码碰到的一些问题

  • 开始

最近想导入 Spring 源码进行阅读,兴致冲冲就去 Github 下载。但是用 git 下载也太慢了吧。开了全局还是龟速,最后还报 error。小问号满脑子都是小朋友???

于是就直接下载了 zip 包,解压后有个 import-to-idea.md ,打开看一看。

The following has been tested against IntelliJ IDEA 2016.2.2

## Steps

_Within your locally cloned spring-framework working directory:_

1. Precompile `spring-oxm` with `./gradlew :spring-oxm:compileTestJava`
2. Import into IntelliJ (File -> New -> Project from Existing Sources -> Navigate to directory -> Select build.gradle)
3. When prompted exclude the `spring-aspects` module (or after the import via File-> Project Structure -> Modules)
4. Code away

## Known issues

1. `spring-core` and `spring-oxm` should be pre-compiled due to repackaged dependencies.
See `*RepackJar` tasks in the build and https://youtrack.jetbrains.com/issue/IDEA-160605).
2. `spring-aspects` does not compile due to references to aspect types unknown to
IntelliJ IDEA. See https://youtrack.jetbrains.com/issue/IDEA-64446 for details. In the meantime, the
'spring-aspects' can be excluded from the project to avoid compilation errors.
3. While JUnit tests pass from the command line with Gradle, some may fail when run from
IntelliJ IDEA. Resolving this is a work in progress. If attempting to run all JUnit tests from within
IntelliJ IDEA, you will likely need to set the following VM options to avoid out of memory errors:
    -XX:MaxPermSize=2048m -Xmx2048m -XX:MaxHeapSize=2048m
4. If you invoke "Rebuild Project" in the IDE, you'll have to generate some test
resources of the `spring-oxm` module again (`./gradlew :spring-oxm:compileTestJava`)    


## Tips

In any case, please do not check in your own generated .iml, .ipr, or .iws files.
You'll notice these files are already intentionally in .gitignore. The same policy goes for eclipse metadata.

## FAQ

Q. What about IntelliJ IDEA's own [Gradle support](https://confluence.jetbrains.net/display/IDEADEV/Gradle+integration)?

A. Keep an eye on https://youtrack.jetbrains.com/issue/IDEA-53476

步骤 1 是先用 gradle 预编译 spring-oxm,于是 brew install gradle 安装完成后,cd 到 spring-framework-master 文件夹,然后执行 gradlew :spring-oxm:compileTestJava

  • 碰到问题
    首先碰到的是 Build scan background action failed ,有博客说“中间可能会各种报错,可能都是网络原因,多试几次就好了”。之前用 git 下源码确实会因为网络报错,编译应该不会,但是俺还是湿了好多次。
Build scan background action failed.
org.gradle.process.internal.ExecException: Process 'command 'git'' finished with non-zero exit value 128
        at org.gradle.process.internal.DefaultExecHandle$ExecResultImpl.assertNormalExitValue(DefaultExecHandle.java:417)
        at org.gradle.process.internal.DefaultExecAction.execute(DefaultExecAction.java:38)
        at org.gradle.process.internal.DefaultExecActionFactory.exec(DefaultExecActionFactory.java:152)
        at io.spring.ge.BuildScanConventions.exec(BuildScanConventions.java:162)
        at io.spring.ge.BuildScanConventions.addGitMetadata(BuildScanConventions.java:111)
        at com.gradle.scan.plugin.internal.api.j.a(SourceFile:22)
        at com.gradle.scan.plugin.internal.api.k$a.a(SourceFile:112)
        at com.gradle.scan.plugin.internal.api.h.a(SourceFile:61)
        at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:515)
        at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
        at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
        at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
        at java.base/java.lang.Thread.run(Thread.java:834)

还碰到了一个fatal: not a git repository,于是搜了一下问题,发现碰到的大多是 gradle ,idea 版本的问题。然后想尝试直接第二部导入 idea 用 gradle 编译,过了半个多小时最后还是报错了 。 T T

- 尝试解决
看到大多数博客说是 gradle 版本的原因,我的版本是 Gradle 6.0.1 ,但是我想先试试 not a git repository 的问题。于是把 spring-framewor-master 文件夹移到了 github 下面,然后在 github desktop 上添加这个repository 。
再来 terminal 试试 gradlew :spring-oxm:compileTestJava

> Task :spring-oxm:genJaxb
[ant:javac] : warning: 'includeantruntime' was not set, defaulting to build.sysclasspath=last; set to false for repeatable builds
[ant:javac] 警告: [options] 未与 -source 8 一起设置引导类路径
[ant:javac] 1 个警告

> Task :spring-beans:compileGroovy
注: /Users/chenzhijie/Documents/GitHub/spring-framework-master/spring-beans/build/tmp/compileGroovy/groovy-java-stubs/org/springframework/beans/factory/groovy/GroovyDynamicElementReader.java使用或覆盖了已过时的 API。
注: 有关详细信息, 请使用 -Xlint:deprecation 重新编译。

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.4/userguide/command_line_interface.html#sec:command_line_warnings

BUILD SUCCESSFUL in 1m 59s
40 actionable tasks: 40 executed

最后终于成功了~
如果有类似问题的小伙伴可以试一下,但是每台电脑环境都不太一样,不是一定有效。

你可能感兴趣的:(spring,spring,源码,gradle)