[Code] Gradle

Jongjin Na·2022년 10월 28일
1

CODE

목록 보기
2/5
post-thumbnail

Gradle

그냥 TIL처럼 프로그래밍 공부하면서 배운거 간단하게 적을거야.

2022.10.28.

gradle project 가 import가 안되는 문제.
gradle 파일이 다운로드가 되지 않아, 실행조차 할 수 없음.

Connect timed out

비슷한 문제

Gradle sync failed: Connection timed out: connect.

해당 문제 해결법 중 하나인 방화벽을 끄는 방법을 하고 다시 실행해도 같은 문제 발생.

gradle-wrapper.properties

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

gradle-wrapper.properties 파일을 찾게되어 확인해봄.
해당 디스크에 파일이 있으면 그 파일을 사용하고, 없으면 다운받는 형식.

[그래들] gradle-wrapper.properties에 대해

wrapper/dists

gradle-7.5.1-bin.zip.lck
gradle-7.5.1-bin.zip.part

gradle을 import하면 위 두 파일만 만들어지고 이후 실행이 안됨. //

https\://services.gradle.org/distributions/gradle-7.5.1-bin.zip

해당 파일을 압축해제 후 해당 자리에 넣어줘도 인식을 못함.

gradle-wrapper

The Gradle Wrapper

The recommended way to execute any Gradle build is with the help of the Gradle Wrapper (in short just “Wrapper”). The Wrapper is a script that invokes a declared version of Gradle, downloading it beforehand if necessary. As a result, developers can get up and running with a Gradle project quickly without having to follow manual installation processes saving your company time and money.

The Wrapper workflow

위 사이트 방법을 따라 실행해보았다.
Adding은 이미 파일이 있기에 넘어가고,
Using 단계를 실행하자.

$ gradlew.bat build

이를 실행하면

Downloading https://services.gradle.org/distributions/gradle-7.5.1-bin.zip

Exception in thread "main" java.io.IOException: Downloading from https://services.gradle.org/distributions/gradle-7.5.1-bin.zip failed: timeout
        at org.gradle.wrapper.Download.downloadInternal(Download.java:122)                                                                     
....
Caused by: java.net.SocketTimeoutException: connect timed out                                                                                  
        at java.base/java.net.PlainSocketImpl.waitForConnect(Native Method)       
....

이런 에러가 발생한다.
java.net.SocketTimeoutException: connect timed out
소켓타임아웃이 문제였다.

Connection Timeout

타임아웃정리

  • 정의
      - 클라이언트가 서버측으로 Connection을 맺길 원하지만, 서버의 장애 상황으로 connection조차 맺어지지 못할 때 발생하는 timeout
  • Connection 과정
      - TCP 소켓 통신에서 클라이언트와 서버가 연결(Connection)될 때 정확한 전송을 보장하기 위해 상대방 컴퓨터와 사전에 세션을 수립함. 이 과정을 3-Way handshake라고 함 
      - 3-way handshake가 정상적으로 끝나야 Connection이 됐다고 표현할 수 있음
      - 즉, Connection Timeout이란 3-way HandShake가 정상적으로 수행되어 서버에 연결되기까지 소요된 시간임
  • TCP 3-Way Handshake 절차
      (1) A클라이언트는 B서버에 접속을 요청하는 SYN패킷을 보낸다. 이때 A클라이언트는 SYN 을 보내고 SYN/ACK 응답을 기다리는SYN_SENT 상태가 되는 것이다.
      (2) B서버는 SYN요청을 받고 A클라이언트에게 요청을 수락한다는 ACK 와 SYN flag 가 설정된 패킷을 발송하고 A가 다시 ACK으로 응답하기를 기다린다. 이때 B서버는 SYN_RECEIVED 상태가 된다.
      (3) A클라이언트는 B서버에게 ACK을 보내고 이후로부터는 연결이 이루어지고 데이터가 오가게 되는것이다. 이때의 B서버 상태가 ESTABLISHED 이다.
  • 이런거 잘 모르겠고 어떻게 해결하지.
    서버쪽에서 응답을 안보내준거같은데, 방화벽에 막힌건가..
    점점 나의 범위를 넘어선거같은데,

    같은 문제 발견!

    intellij에서 java.net.SocketTimeoutException

    나와 같은 문제가 발생한 포스트를 찾음.

    방화벽 허용이 떠서 허용했더니 된 듯.
    결론 코드나 설정 문제는 아니고 방화벽 때문에 인듯.

    음,, 방화벽 허용은 어떻게 하지.. 내 권한 밖인데...

    2022.10.31.

    Customizing

    Customizing the Gradle Wrapper

    Customizing the Gradle Wrapper
    Most users of Gradle are happy with the default runtime behavior of the Wrapper. However, organizational policies, security constraints or personal preferences might require you to dive deeper into customizing the Wrapper. Thankfully, the built-in wrapper task exposes numerous options to bend the runtime behavior to your needs. Most configuration options are exposed by the underlying task type Wrapper.

    인증된 Gradle 을 다운받아보자.

    Specifying the HTTP Basic Authentication credentials using system properties

    systemProp.gradle.wrapperUser=username
    systemProp.gradle.wrapperPassword=password

    accessing_the_web_via_a_proxy

    Configuring an HTTP proxy using gradle.properties

    systemProp.https.proxyHost=www.somehost.org
    systemProp.https.proxyPort=8080
    systemProp.https.proxyUser=userid
    systemProp.https.proxyPassword=password
    # NOTE: this is not a typo.
    systemProp.http.nonProxyHosts=*.nonproxyrepos.com|localhost

    Configuring a SOCKS proxy using gradle.properties

    systemProp.socksProxyHost=www.somehost.org
    systemProp.socksProxyPort=1080
    systemProp.java.net.socks.username=userid
    systemProp.java.net.socks.password=password

    하.. 프록시가 어쩌구 이런거 잘 몰라요.
    그러다가 새로운 해결법? 을 찾아보았다.

    Offline 환경

    [spring] offline 환경에서 gradle 빌드 환경 세팅

    방화벽에 막혔다면, 인터넷이 없다고 생각하고 시작하면 되지 않나? 라는 생각을 통한 방법이다.

    gradle 자체가 없어서 build가 불가한 경우
    /gradle/wrapper/ 에 gradle bin 파일을 넣습니다. https://gradle.org/releases/
    /gradle/wrapper/gradle-wrapper.properties의 distributionUrl을 다음과 같이 변경합니다.

    해당 방법이 가장 적절할 거 같아서 실행해봤다.
    해당 bin 파일이 다운로드가 잘 되더니, build.gradle 파일에서 에러가 발생했다.

    Plugin [id: 'org.springframework.boot', version: '2.7.5'] was not found in any of the following sources:

    일단 connet timed out 에러는 사라진거같다.

    gradlew.bat build --debug

    디버그로 더 많은 로그를 살펴본 결과, connet timed out 에러는 아직도 있는걸로,,

    Plugin error

    [Spring Boot] Plugin [id: 'org.springframework.boot'...]

    추측을 해보자면 방화벽때문에 gradle-wrapper.properties의 distributionUrl을 못가져오고 있는 것 같다는 게 이유인 것 같다.

    찾다가,, 또 발견, 하지만 maven을 사용하는 분이다.
    이제는 공부보다는 그냥 해결이 되었으면 하는 마음이다.. gradle 적용해보자.

    사실 그런거 상관없네./ ㅎㅎ

    # 수정 후
    
    buildscript {
    	repositories {
    		mavenLocal()
    		maven { url 'https://maven.aliyun.com/repository/google/' }
    		maven { url 'https://maven.aliyun.com/repository/public/' }
    		maven { url 'https://maven.aliyun.com/repository/spring/' }
    		maven { url 'https://maven.aliyun.com/repository/gradle-plugin/' }
    		maven { url 'https://maven.aliyun.com/repository/spring-plugin/' }
    		maven {
    			url "https://plugins.gradle.org/m2/"
    		}
    		mavenCentral()
    	}
    	dependencies {
    		classpath("org.springframework.boot:spring-boot-gradle-plugin:2.5.6")
    		classpath "io.spring.gradle:dependency-management-plugin:1.0.11.RELEASE"
    	}
    }
    
    plugins {
    	id 'java'
    }
    
    apply plugin: "org.springframework.boot"
    apply plugin: "io.spring.dependency-management"

    바로 적용해서 실행했다.

    > root project > Resolve dependencies of :classpath > dependency-management-plugin-1.0.15.RELEASE.pom
    > root project > Resolve dependencies of :classpath > spring-boot-gradle-plugin-2.7.5.pom

    resolve 하는데 한참이다.. 계속 기다려봤는데도 안되서, 또 찾아봤다.

    Closing given the lack of reaction and the description most likely indicates a networking / setup issue.
    Would need at least a stacktrace or a reproducer as requested before re-opening.

    Gradle can't resolve dependencies classpath

    또 네트워크, 또 방화벽..

    하,. 진짜 모르겠다.. 나중에 하자. 나중에 되겠지.

    다시 처음부터.

    인트라넷 개발환경 잡기 (intelliJ with gradle offline)

    지금 너무 머리가 아프니, 이거는 내일 실행해보기로 한다.
    이것저것 생각하지 않고, gradle, plugin을 따로 설치한 다음에 연결해보자. 처음부터!

    2022.11.14.

    오랜만.

    회사 방화벽 gradle 적용 안될때 해결 방법

    오랜만에 다시 해보기로 했다.
    방화벽이 문제면, 보안을 안타는 방법으로 가면 되지 않나?

    distributionUrl=https\://services.gradle.org/distributions/gradle-7.5.1-bin.zip
    --->
    distributionUrl=http\://services.gradle.org/distributions/gradle-7.5.1-bin.zip

    네, 안됩니다.

    Invalid Http response

    없다고 뜨네요,..

    다시 차근차근.

    위 방법이 안되자 이전에 해본 방법인 미리 gradle을 다운받고 해당 파일을 받는 방법을 다시 해봤다.

    * Exception is:
    org.gradle.api.plugins.UnknownPluginException: Plugin [id: 'org.springframework.boot', version: '2.7.5'] was not found in any of the following sources:
    

    해당 오류가 발생해고, 이는
    인프런 질문
    이 문제와 같았다. 그래서 네트워크 문제임을 다시 한번 확인하고,

    JDK와 intellij cacert파일에 사내 ssl 인증서를 등록하는 방법

    해당 방법을 찾기로 했다.

    intellij Server Certificates.

    intellij Server Certificates 문제

    1. SSL 통신 관련 옵션을 해제(별로 추천하고 싶지는 않지만..인증서가 없다면 이 방법으로 간다.)
    • File > Settings > Tools > Server Certificates > Accept non-trusted certificates automatically 체크
    • Appearance & Behavior > System Settings > Updates > Use Secure connection 체크 해제

    해당 방법을 통해서 해보자!

    • Appearance & Behavior > System Settings > Updates > Use Secure connection 체크 해제

    이거 왜 없지,, 나중에 확인해보자.

    [참고] 오프라인 환경에서.

    [spring] offline 환경에서 gradle 빌드 환경 세팅

    좋은 자료.
    지금 해결 안되도, 나중에 사용가능해보임.

    Q.
    어떻게 실행하지..

    profile
    안녕하세요. 나종진입니다.

    0개의 댓글