Timetombs

泛义的工具是文明的基础,而确指的工具却是愚人的器物

66h / 117a
,更新于 2024-12-21T13:29:20Z+08:00 by   2255bb5

[Java] Install

版权声明 - CC BY-NC-SA 4.0

1 OpenJdk

下载地址 :

  1. https://adoptium.net/
  2. https://www.microsoft.com/openjdk
  3. https://developers.redhat.com/products/openjdk/download
# 设置环境变量 
Env-SetJavaEnvironmentVariable

# 查看版本信息 
java -version

2 Maven

下载地址 : https://maven.apache.org/download.cgi

下载二进制包 : apache-maven-3.8.1-bin.zip解压至d:\_app\_maven\目录下。

# 设置环境变量
Env-SetMavenEnvironmentVariable

# 查看版本信息
mvn -v

# wrapper
# https://github.com/takari/maven-wrapper
mvn --non-recursive --debug io.takari:maven:wrapper -Dmaven='3.8.1'

2.1 settings.xml

复制settings.xml配置文件到HOME/.m2/目录。

<?xml version="1.0" encoding="UTF-8"?>
<!-- https://maven.apache.org/settings.html -->
<!--
  加载顺序
  1. 全局设置 M2_HOME/conf/settiing.xml
  2. 用户设置 HOME/.m2/settiing.xml
-->
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd">

  <localRepository>/lnh/_cache/_maven</localRepository>
  <!-- <localRepository>d:/_cache/_maven</localRepository> -->

  <profiles>
    <profile>
      <!-- /lib/maven-model-builder-${version}.jar -->
      <!-- /org/apache/maven/model/pom-4.0.0.xml -->
      <id>default</id>
      <repositories>
        <repository>
          <id>central</id>
          <url>https://repo1.maven.org/maven2/</url>
          <snapshots>
            <enabled>false</enabled>
          </snapshots>
        </repository>
      </repositories>
      <pluginRepositories>
        <pluginRepository>
          <id>central</id>
          <url>https://repo1.maven.org/maven2/</url>
          <snapshots>
            <enabled>false</enabled>
          </snapshots>
        </pluginRepository>
      </pluginRepositories>
    </profile>
    <profile>
      <!-- https://developer.aliyun.com/mvn/guide -->
      <id>aliyun</id>
      <repositories>
        <repository>
          <id>public</id>
          <url>https://maven.aliyun.com/repository/public</url>
        </repository>
        <repository>
          <id>central</id>
          <url>https://maven.aliyun.com/repository/central</url>
        </repository>
        <repository>
          <id>jcenter</id>
          <url>https://maven.aliyun.com/repository/jcenter</url>
        </repository>
        <repository>
          <id>spring</id>
          <url>https://maven.aliyun.com/repository/spring</url>
        </repository>
        <repository>
          <id>gradle-plugin</id>
          <url>https://maven.aliyun.com/repository/gradle-plugin</url>
        </repository>
        <repository>
          <id>google</id>
          <url>https://maven.aliyun.com/repository/google</url>
        </repository>
        <repository>
          <id>grails-core</id>
          <url>https://maven.aliyun.com/repository/grails-core</url>
        </repository>
      </repositories>
      <pluginRepositories>
        <pluginRepository>
          <id>public</id>
          <url>https://maven.aliyun.com/repository/public</url>
        </pluginRepository>
        <pluginRepository>
          <id>central</id>
          <url>https://maven.aliyun.com/repository/central/</url>
        </pluginRepository>
        <pluginRepository>
          <id>jcenter</id>
          <url>https://maven.aliyun.com/repository/jcenter</url>
        </pluginRepository>
        <pluginRepository>
          <id>spring</id>
          <url>https://maven.aliyun.com/repository/spring</url>
        </pluginRepository>
        <pluginRepository>
          <id>gradle-plugin</id>
          <url>https://maven.aliyun.com/repository/gradle-plugin</url>
        </pluginRepository>
        <pluginRepository>
          <id>google</id>
          <url>https://maven.aliyun.com/repository/google</url>
        </pluginRepository>
        <pluginRepository>
          <id>grails-core</id>
          <url>https://maven.aliyun.com/repository/grails-core</url>
        </pluginRepository>
      </pluginRepositories>
    </profile>
  </profiles>

  <activeProfiles>
    <activeProfile>aliyun</activeProfile>
    <activeProfile>default</activeProfile>
  </activeProfiles>
</settings>

3 Gradle

下载地址 : https://gradle.org/releases/

下载二进制包 : gradle-6.7-bin.zip解压至d:\_app\_gradle\目录下。
设置环境变量 :

# 设置环境变量
Env-SetGradleEnvironmentVariable

# 查看版本信息
gradle -v

# wrapper
# https://docs.gradle.org/current/userguide/gradle_wrapper.html
gradle wrapper --gradle-version 6.7 --distribution-type all

3.1 gradle.properties

复制gradle.properties配置文件到GRADLE_USER_HOME目录。

# https://docs.gradle.org/current/userguide/build_environment.html
# GRADLE_USER_HOME/gradle.properties
org.gradle.warning.mode=all
org.gradle.caching=true
org.gradle.daemon=true
# milliseconds 1 hours
org.gradle.daemon.idletimeout=3600000
org.gradle.parallel=true
org.gradle.jvmargs=-XX:+HeapDumpOnOutOfMemoryError -Xmx1024m -Dfile.encoding=UTF-8 -Duser.country=CN -Duser.language=en -Duser.variant

3.2 init.gradle

复制init.gradle配置文件到GRADLE_USER_HOME目录。

// GRADLE_USER_HOME/init.gradle
gradle.allprojects {
  ext {
    // https://help.aliyun.com/document_detail/102512.html
    MAVEN_REPOSITORY_MIRROR_URL_MAP = [
      '//repo1.maven.org/maven2'         : 'https://maven.aliyun.com/repository/central',
      '//repo.maven.apache.org/maven2'   : 'https://maven.aliyun.com/repository/central',
      '//jcenter.bintray.com'            : 'https://maven.aliyun.com/repository/jcenter',
      '//maven.google.com'               : 'https://maven.aliyun.com/repository/google',
      '//plugins.gradle.org/m2'          : 'https://maven.aliyun.com/repository/gradle-plugin',
      '//repo.spring.io/release'         : 'https://maven.aliyun.com/repository/spring',
      '//repo.spring.io/milestone'       : 'https://maven.aliyun.com/repository/spring',
      '//repo.spring.io/libs-milestone'  : 'https://maven.aliyun.com/repository/spring',
      '//repo.spring.io/plugins-release' : 'https://maven.aliyun.com/repository/spring-plugin',
      '//repo.grails.org/grails/core'    : 'https://maven.aliyun.com/repository/grails-core'
    ]

    findMavenRepositoryMirrorUrl = {
      for(item in MAVEN_REPOSITORY_MIRROR_URL_MAP){
        if(it.contains(item.key)){
          return item.value
        }
      }
    }

    tryReplaceWithMavenRepositoryMirrorUrl = { type, repository ->
      if(repository instanceof MavenArtifactRepository){
        originalUrl = repository.url.toString()
        mirrorUrl = findMavenRepositoryMirrorUrl(originalUrl)
        if(mirrorUrl){
          repository.setUrl(mirrorUrl)
          logger.info("${type} : use ${repository.url} replace ${originalUrl}")
        }else{
          logger.info("${type} : use ${repository.url}")
        }
      }
    }
  }

  buildscript {
    repositories {
      all { repository -> 
        tryReplaceWithMavenRepositoryMirrorUrl('buildscript.repositories', repository)
      }
    }
  }

  repositories {
    all { repository -> 
      tryReplaceWithMavenRepositoryMirrorUrl('repositories', repository)
    }
  }
}

3.3 settings.gradle

复制settings.gradle配置文件到GRADLE_USER_HOME目录。

pluginManagement {
  repositories {
    maven {
      url 'https://maven.aliyun.com/repository/gradle-plugin'
    }
    gradlePluginPortal()
  }
}
下一篇 : [Java] Tool