IDEA uses Gradle to compile Spring source code

The IDEA used in this article is the community version. Source code compilation address (pull it locally or fork to its own git repository): https://github.com/Nuclear-Core-Learning/spring-framework 

IDEA download address: https://www.jetbrains.com/idea/download/other.html

table of Contents

Preface

prerequisites

Gradle download

Gradle decompression

Configure environment variables

Test installation

Before compilation

Import IDEA

IDEA Spring source code construction

JDK8 and later versions depend on


Preface

  • The spirng-framework source code starts from 5.0 and uses gradle as a compilation tool
  • spirng-framework source code compilation is a test of network speed (network jitter may cause compilation failure)
  • The source code of spirng-framework must be configured with domestic maven warehouse addresses such as Alibaba Cloud, etc.
  • spirng-framework source code compilation must be configured with large JVM parameters, otherwise it may fail due to insufficient memory allocation
  • The compiled version of spirng-framework source code generally uses 1.8 or more
  • The IDEA and Gradle versions of the spirng-framework source code are the key to success (2018.3 compilation conflict, 2019.3 success)
  • spirng-framework source code supports Eclipse and IDEA import

prerequisites

JDK/JRE (version 7 or above) has been installed, here is Win10 system

Enter on the command line: java -version to query the version installed on the current computer

Gradle download

Download the latest release package of Gradle from  Gradle's official website .

up-e64ccba5723a626b2f5841ec117740f876b.png

Gradle decompression

The Gradle distribution package is a ZIP file. The complete distribution package includes the following contents (the official distribution package has a full version, and also a version without source code and documentation, which can be downloaded as required. [Rover12421] Annotation):

  • Gradle executable
  • User manual (available in PDF and HTML versions)
  • DSL Reference Guide
  • API manual (Javadoc and Groovydoc)
  • Samples, including examples in the user manual, some complete build samples and more complex build scripts
  • Source code. For reference only, if you want to compile Gradle yourself, you need to check out the release version source code from the source code repository. For details, please check the official Gradle homepage.

Configure environment variables

To run gradle, you must add GRADLE_HOME/bin to your PATH environment variable.

Test installation

Run the following command to check whether the installation is successful. The command will display the current JVM version and Gradle version.

gradle -v 

 JVM parameter configuration

The JVM parameters of Gradle runtime can be set through GRADLE_OPTS or JAVA_OPTS. These parameters will take effect at the same time. The parameters set by JAVA_OPTS will be shared with other JAVA applications. A typical example is that the proxy can be set in JAVA_OPTS and the memory parameters can be set in GRADLE_OPTS. At the same time, these parameters can also be set at the beginning of the gradle or gradlew script file.

Before compilation

1. cd into the spring-framework code directory

2. Modify sesstings.gradle to set the Alibaba Cloud warehouse address

pluginManagement {
	repositories {
		gradlePluginPortal()
		maven { url 'https://maven.aliyun.com/repository/public' }
		maven { url 'https://repo.spring.io/plugins-release' }
	}
}

3. Modify build.gradle and still add Alibaba Cloud warehouse address

repositories {
			maven { url 'https://maven.aliyun.com/nexus/content/groups/public' }
			maven { url 'https://maven.aliyun.com/nexus/content/repositories/jcenter' }
			mavenCentral()
			maven { url "https://repo.spring.io/libs-spring-framework-build" }
		}

4. Modify gradle.properties and increase the JVM parameters

version=5.3.3-SNAPSHOT
org.gradle.jvmargs=-Xmx2048M
org.gradle.caching=true
org.gradle.parallel=true
kotlin.stdlib.default.dependency=false

5. Compile spring-oxm

Import IDEA

1. Select existing project resources to import

2. Select the spring-framework source directory

3. Select Gradle project

4. Import project parameter configuration

 

 

IDEA Spring source code construction

2018.3.4 https://youtrack.jetbrains.com/issue/IDEA-207327?_ga=2.262020813.155240518.1608166853-1295022405.1581304547

More: https://www.jetbrains.com/idea/download/other.html

Note: Looking at the release log, some of the problems with Gradle have been fixed.

gradle-wrapper.properties, specify that the gradle toolkit is 6.7.1 (Idea 2018.3 was compiled successfully, you can also change it to 6.1 to have a try, it is best to keep the environment and configuration version consistent)

distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-6.7.1-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists

Download https://services.gradle.org/distributions/gradle-6.1-bin.zip (97.47 MB)
Download https://services.gradle.org/distributions/gradle-6.1-bin.zip finished succeeded, took 1 m 52 s 622 ms
Starting Gradle Daemon...
Gradle Daemon started in 6 s 517 ms
> Task :buildSrc:compileJava
> 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
> 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:validatePlugins UP-TO-DATE
> Task :buildSrc:check UP-TO-DATE
> Task :buildSrc:build UP-TO-DATE

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

CONFIGURE SUCCESSFUL in 8m 52s

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

CONFIGURE SUCCESSFUL in 8m 46s

Note: The occurrence of java.lang.NoClassDefFoundError: org/gradle/api/internal/plugins/DefaultConvention means that Idea and Gradle versions are not compatible.

JDK8 and later versions depend on

spring-core

The latest JDK download link: https://www.oracle.com/cn/java/technologies/javase-downloads.html 

Account: [email protected]
Password: Oracle123

Download 11LTS stable long-term maintenance version:

problem solved!

Guess you like

Origin blog.csdn.net/boonya/article/details/111357056