When building systems, tools such as Ant and Maven are often used. For beginners, they are still too complicated and it still takes time to get started. This article will introduce readers to a new way to build a project gradle. It is simple and quick to get started and can greatly save project time and cost.
1. Download and configure Gradle
Gradle Inc. is a Gradle framework development company that provides Gradle tools support for Eclipse IDE. This tool can create and allow Gradle projects to be imported into the Eclipse IDE. It also allows running Gradle tasks and monitoring its execution.
First of all, we need to download Gradle. The download path is Gradle. The specific configuration is clearly written on the official website. You can follow the instructions according to your operating system and follow the instructions step by step. Here I will take Windows 10 as an example.
After downloading, decompress to the C:/Gradle directory. Then, you need to configure the environment variables, and the entire configuration process is as follows:
Next, verify that the environment variables are effective and correct, open the cmd command line, and execute the gradle -v command. If the following information appears, it means that the configuration is effective.
Then, you need to configure the path of gradle into Eclipse, as shown below,
Finally, install the plug-in that integrates Gradle with Eclipse, which calls Gradle's plug-in Buildship. The source code of Buildship can be obtained on Github.
2. Install the Eclipse Gradle (Buildship) tool plugin
2.1 Install in Eclipse Marketplace
The easiest way to install the Eclipse Gradle tool is to use Marketplace in Eclipse. The version of Eclipse on my machine is: Neon.3 Release (4.6.3), and the specific operation steps are:
In the pop-up window, enter "Buildship" and press Enter to search.
Then click Install and agree to the agreement. After the installation is completed, you need to restart Eclipse.
2. 2 Install through Eclipse Update Manager
You can also click the Help ▸ Install New Software menu on the menu bar on Eclipse to install Gradle tools.
Taking my Eclipse 4.6 (Neon) version as an example, you can install it using http://download.eclipse.org/releases/neon. As shown below.
Then click the Next button to perform subsequent installation.
3. Create a new Gradle project
The Eclipse Gradle tool provides a wizard for creating Java-based Gradle projects. You can access it through the "File New Other..." menu item.
Click Next ,
Click the 'Next >' button to configure the local Gradle installation path.
Continue with the Next > button and see the preview information for the new project:
Click the Finish button to create the project. This will trigger gradle init --type java-library command and import the project.
The created project directory structure is as follows:
4. Import existing projects into Eclipse
You can also import existing Gradle projects into Eclipse. Select FileImport...GradleGradle Project menu item.
After clicking the Next> button, you need to specify the root directory of the Gradle project.
Click the Next > button and specify the Gradle runtime settings.
After that, the project import preview is displayed.
Finally, click Finish to end the import.
5. Update Gradle build path and project transformation
5.1 Update Eclipse to the latest modifications using Gradle build files
If the build.gradle file is updated, Eclipse does not automatically update the classpath. Select Gradle Refresh Gradle Project to update.
5.2 Add Gradle support to existing Eclipse projects
To convert a Java project to a Gradle project, right-click the project that needs to be converted and select Gradle Add Gradle Nature .
If the initial Gradle file is not generated, you can run gradle init task.
6. Using Gradle Task View
After successfully importing the Gradle project, the project will be displayed in the Gradle task view.
The selected Gradle task can be run by right-clicking on a Gradle task in the Gradle task view.
You can view the run results in the Gradle Executions view and the Console view.
The above is all the content of this article. I hope it will be helpful to everyone's learning and I hope everyone will support Wulin.com more.