gradle使用 (0 helloworld 程序)

2 篇文章 0 订阅

1 下载gradle  http://services.gradle.org/distributions/

下载需要的版本 ,我这里下载的是  gradle-5.4.1-all.zip, 解压

配置环境变量 ,变量值为解压的路径

path末尾加入  %GRADLE_HOME%\bin;

 在cmd查看 

 配置gradle的 jar的下载地址

allprojects{
    repositories {
        def REPOSITORY_URL = 'http://maven.aliyun.com/nexus/content/groups/public/'
        all { ArtifactRepository repo ->
            if(repo instanceof MavenArtifactRepository){
                def url = repo.url.toString()
                if (url.startsWith('https://repo1.maven.org/maven2') || url.startsWith('https://jcenter.bintray.com/')) {
                    project.logger.lifecycle "Repository ${repo.url} replaced by $REPOSITORY_URL."
                    remove repo
                }
            }
        }
        maven {
            url REPOSITORY_URL
        }
    }
}

这里使用IDEA2019新建一个java项目

 

设置文件名称与生成路径

 等待项目构建完成

目录结构如下

查看build.gradle文件

plugins {
    id 'java'
}

group 'com.shj.gradle'
version '1.0-SNAPSHOT'

sourceCompatibility = 1.8

repositories {
    mavenCentral()
}

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

编写一个测试类

package com.shj;

public class GradleTest1 {

    public static void main(String[] args) {
        System.out.println("hello gradle!");
    }

}

修改 build.gradle

plugins {
    id 'java'
    id 'application'
}


group 'com.shj.gradle'
version '1.0-SNAPSHOT'

sourceCompatibility = 1.8


mainClassName = 'com.shj.GradleTest1'
repositories {
    mavenCentral()
}

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

其中: 加入了 application 插件

  也可以设置为

apply plugin:'application'

 然后设置了程序的mainClassName 

这两个地方都能启动main方法

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Hero_孙

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值