8

配置 Gradle (IDEA) 环境的坑

 3 years ago
source link: https://blog.triplez.cn/posts/err-and-solution-of-config-gradle-idea-env/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

要做个 Entry Task ,兴奋地配置了个 Java 的环境,没想到踩了这么多坑。

Plugin was not found in any of the following sources#

Spring Boot 官方提供了一个 Spring Intializr 以快速初始化项目,选择了 Gradle Project 之后进入项目,IDEA 的 Gradle 同步上一直报如下错误:

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

- Gradle Core Plugins (plugin is not in 'org.gradle' namespace)
- Plugin Repositories (could not resolve plugin artifact 'org.springframework.boot:org.springframework.boot.gradle.plugin:2.1.6.RELEASE')
  Searched in the following repositories:
    Gradle Central Plugin Repository

折腾了半天,搜索了无数解决方案都无效,最后根据这个回答才解决。原因现在还没弄清楚,但是能 work 。 解决方案如下:

build.gradle 文件中的 plugins 是这样的:

plugins {
	id 'org.springframework.boot' version '2.1.6.RELEASE'
	id 'java'
}

更改一下,将 org.springframework.boot 包移出并去掉版本号:

plugins {
    id 'java'
}

apply plugin: 'org.springframework.boot'

于是这个错误就解决了 ;)

Plugin with id ‘org.springframework.boot’ not found#

然而它会变成另外一个错误,如下:

Plugin with id 'org.springframework.boot' not found.

又折腾搜索了一番,发现是缺少 buildscript 。在 build.gradle 文件最前面加入如下内容:

buildscript {
	repositories {
		mavenCentral()
	}
	dependencies {
		classpath 'org.springframework.boot:spring-boot-gradle-plugin:2.1.6.RELEASE'
	}
}

Problem solved !

Connection to the Internet denied.#

遇到这个错误,在 build.gradlerepositories 中换一个 Maven 源即可。

找不到或无法加载主类#

在运行 Spring Boot 的时候遇到了这个问题,在命令行上 gradle buildjar 包是能够正常运行的,然而在 IDEA 里就不能通过 Run Application 正常运行。解决方案其实特别特别简单:右键项目中的 src 文件夹,找到 Mark Directory as ,选择 Sources Root ,重新构建运行项目即可。

折腾个环境花了一天,还是得好好学习啊……


知识共享许可协议
本作品采用知识共享署名-相同方式共享 4.0 国际许可协议进行许可。

Recommend

  • 33
    • 掘金 juejin.im 6 years ago
    • Cache

    Android Gradle进阶配置指南

    简单的总结一下gradle: 1.Gradle是一种构建工具,它可以帮你管理项目中的差异,依赖,编译,打包,部署......你可以定义满足自己需要的构建逻辑,写入到build.gradle中供日后复用. 2.Gradle不是一种编程语言,它不能帮你实现软件中的

  • 82
    • blog.bihe0832.com 5 years ago
    • Cache

    Gradle环境变量那些事

    最近真的是多灾多难,搞各种杂七杂八。带来的现象就是要不停的切换项目和工程,因为网络策略的问题,不同的项目使用了网络代理也不一样。专门去看了下Gradle环境变量相关的内容,然后整理一下。 官方介绍: ...

  • 11
    • www.cnblogs.com 4 years ago
    • Cache

    Maven、Gradle 配置国内镜像源

    Maven 全局配置 修改 Maven 默认的全局配置文件: 类 Unix 系统: Mac OS / Linux 默认在 ~/.m2/settings.xml Windows 系统:一般在 Maven 安装目录的

  • 37
    • www.phodal.com 4 years ago
    • Cache

    Gradle IDEA 的项目模型

    最近在为新的工具 Scie 设计一个模型,以用于描述一个具体的代码工程。而刚好最近也在学习 Gradle 相关的项目模型,便想写一篇文章记录一下相关的模型,以支撑起 Scie 的开发。 ...

  • 15

    Gradle How to get IDEA to detect kotlin generated sources using Gradle ...

  • 12

    [本文结构] 因为墙以及不同开发者的环境的原因,经常会出现clone了一个开源项目以后无法运行的情况,因此专门整理了个人的开源项目在引用或者运行时一些通用的注意事项,其实所...

  • 8
    • www.biaodianfu.com 3 years ago
    • Cache

    Windows+IntelliJ IDEA+Maven环境配置

    Maven简介 在了解Maven之前,我们先来看看一个Java项目需要的东西。首先,我们需要确定引入哪些依赖包。例如,如果我们需要用到commons logging,我们就必须把commons logging的jar包放入classpath。如果我们还需要log4j,就需要把log4j相关的jar包都...

  • 11

    Android入门第14天-AndroidStudio本机开发环境中gradle、sdk以及AVD目录的迁移 ...

  • 8

    手把手教你如何在IDEA中配置Gradle 作者:指北君 2022-11-28 08:23:14 目前大家做Java开发的,无外乎就两种,eclipse或者Intellij IDEA。eclipse是老牌的开发工具,可以说算是我们的初恋了,熟悉的界面,熟悉的快...

  • 4

    Gradle toolchains are rarely a good idea 21 March 2024 The last post featured some Kotlin code inadvertently targeting a new...

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK