본문 바로가기

IT/java

gradle 활용 스크립트 맛보기

반응형

# gradle 버전 :7.4.2

# 신규 자바 프로젝트 만들기

mkdir gradle-app

cd gradle-app

gradle init --type java-library

 

#생성되는 기본 프로젝트 구조

# 기본 명령어

gradle clean

gradle build

gradle jar

 

# 기본 생성된 build.gradle

/*
 * This file was generated by the Gradle 'init' task.
 *
 * This generated file contains a sample Java library project to get you started.
 * For more details take a look at the 'Building Java & JVM projects' chapter in the Gradle
 * User Manual available at https://docs.gradle.org/7.4.2/userguide/building_java_projects.html
 */

plugins {
    // Apply the java-library plugin for API and implementation separation.
    id 'java-library'
}

repositories {
    // Use Maven Central for resolving dependencies.
    mavenCentral()
}

dependencies {
    // Use JUnit Jupiter for testing.
    testImplementation 'org.junit.jupiter:junit-jupiter:5.8.1'

    // This dependency is exported to consumers, that is to say found on their compile classpath.
    api 'org.apache.commons:commons-math3:3.6.1'

    // This dependency is used internally, and not exposed to consumers on their own compile classpath.
    implementation 'com.google.guava:guava:30.1.1-jre'
}

tasks.named('test') {
    // Use JUnit Platform for unit tests.
    useJUnitPlatform()
}

plugins 가 전체 프로젝트의 명령어를 정의한다!

 

일반적으로 생각하는 자바프로젝트는

 

gradle init --type java-appliation

 

으로 해야함!

 

# 이클립스 프로젝트로 바꾸기

## id 'eclipse' 추가

plugins {
    // Apply the application plugin to add support for building a CLI application in Java.
    id 'application'
    id 'eclipse'
}

 

## gradle eclipse 실행

폴더 내에 .setting 등 이클립스 관련 파일 생성

 

## 이클립스에서 프로젝트 임포트

 

## 프로젝트 오른쪽 클릭 후 Configure > Add Gradle Nature

 

# Task 에 대해 알아보자.

 

샘플 build.gradle 안에 아래 추가

task hello {
	doLast {
    	println();
        println("====================");
        println("Welcome to Gradle!");
        println("====================");
        println();
    }
}

# 실행

gradle hello

 

# 내용만 보기

gradle -q hello

 

# 플러그인 java

id 'java' 

추가 후

gradle java

 

 

반응형