Gradle学习笔记(二)--创建Java项目

本文详细介绍了如何使用Gradle构建项目,并通过配置文件应用Java插件,设置仓库来解决依赖问题,最终成功引入gson库,实现项目功能。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

一、新建Gradle Project,点下一步输入项目名

1、在Gradle distribution选择Local installation directory,填写Gradle Home路径

E:\gradle-2.11

2、在Advanced options里填写Gradle user home directory,这只存放gradle下载的jar包的路径,默认在C盘的User文件夹下

E:\gradle

3、点下一步,在点击finish就完成项目创建

二、build.gradle文件

apply plugin: 'java'

// In this section you declare where to find the dependencies of your project
repositories {
    // Use 'jcenter' for resolving your dependencies.
    // You can declare any Maven/Ivy/file repository here.
    jcenter() //gradle默认的中央仓库
    mavenCentral() //自己添加的Maven中央仓库
}

// In this section you declare the dependencies for your production and test code
dependencies {
    // The production code uses the SLF4J logging API at compile time
    compile 'org.slf4j:slf4j-api:1.7.14'
    compile 'com.google.code.gson:gson:2.6.2' //添加自己要用的jar包依赖
    
    // Declare the dependency for your favourite test framework you want to use in your tests.
    // TestNG is also supported by the Gradle Test task. Just change the
    // testCompile dependency to testCompile 'org.testng:testng:6.8.1' and add
    // 'test.useTestNG()' to your build script.
    testCompile 'junit:junit:4.12'
}

右键项目,选择Gradle--》Refresh Gradle Project将自动下载依赖

至此,就可以使用gson包了

Gradle学习笔记(一)--环境搭建

转载于:https://my.oschina.net/yuewawa/blog/657974

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值