gradle - gradle bootRun 执行失败

标签 gradle groovy spring-boot netflix-eureka

我正在尝试运行我的 springboot 应用程序...这一切都是从我将 eureka spring-cloud 插件添加到我的 gradle.build 文件中开始的:

编译'org.springframework.cloud:spring-cloud-starter-eureka'

当我运行“gradle bootRun”时,我收到此错误:

由以下原因引起:java.io.IOException:无法运行程序“C:\Program Files\Java\jdk1.8.0_91\bin\java.exe”。 CreateProcess 错误=206,文件名太长。

我的build.gradle是:

import java.text.SimpleDateFormat

buildscript {
  ext {
    springBootVersion = '1.3.2.RELEASE'
    elasticSearchVersion = '2.2.0'
    groovyVersion = '2.4.5'
  }
  repositories {
    jcenter()
    mavenCentral()
  }
  dependencies {
    classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
    classpath 'io.spring.gradle:dependency-management-plugin:0.5.5.RELEASE'
    classpath 'com.github.ben-manes:gradle-versions-plugin:0.12.0'
    classpath 'org.kordamp.gradle:stats-gradle-plugin:0.1.5'
  }
}

apply plugin: 'java'
apply plugin: 'groovy'
apply plugin: 'eclipse-wtp'
apply plugin: 'idea'
apply plugin: 'spring-boot'
apply plugin: 'io.spring.dependency-management'
apply plugin: 'com.github.ben-manes.versions'
apply plugin: 'org.kordamp.gradle.stats'

def buildDate = new SimpleDateFormat('yyyyMMdd-hhmmss').format(new Date())
version = '1.0.RC1.' + buildDate

sourceCompatibility = 1.8
targetCompatibility = 1.8

repositories {
  jcenter()
  mavenCentral()
  maven { url "https://repo.spring.io/snapshot" }
  maven { url "https://repo.spring.io/milestone" }
}

ext['elasticsearch.version'] = elasticSearchVersion
ext['groovy.version'] = groovyVersion
ext['guava.version'] = '18.0'
ext['lombok.version'] = '1.16.6'

dependencyManagement {
  imports {
    mavenBom "org.springframework.boot:spring-boot-starter-parent:${springBootVersion}"
    mavenBom "org.springframework.cloud:spring-cloud-starter-parent:Brixton.M5"
    mavenBom 'io.spring.platform:platform-bom:2.0.2.RELEASE'
  }
}

dependencies {
  compile('org.springframework.boot:spring-boot-starter-actuator')
  compile('org.springframework.boot:spring-boot-starter-aop')
  compile('org.springframework.boot:spring-boot-starter-cache')
  compile('org.springframework.cloud:spring-cloud-starter-hystrix')    
  compile 'org.jadira.usertype:usertype.extended:5.0.0.GA'
  compile('org.springframework.boot:spring-boot-starter-data-jpa')
  compile('org.springframework.boot:spring-boot-starter-data-rest')
  //compile('org.springframework.data:spring-data-rest-hal-browser')
  compile('org.springframework.boot:spring-boot-devtools')
  compile('org.springframework.boot:spring-boot-starter-hateoas')
  compile('org.projectlombok:lombok')
  compile('org.springframework.boot:spring-boot-starter-thymeleaf')
  compile('org.springframework.boot:spring-boot-starter-web')
  compile "org.elasticsearch:elasticsearch:${elasticSearchVersion}"
  compile 'commons-lang:commons-lang'
  compile 'commons-codec:commons-codec'
  compile 'commons-collections:commons-collections'
  compile 'com.fasterxml.jackson.datatype:jackson-datatype-jsr310'
  compile 'org.springframework.boot:spring-boot-starter-freemarker'  
  compile 'de.codecentric:spring-boot-admin-starter-client:1.3.2'    
  compile 'org.flywaydb:flyway-core'    
  compile('com.domingosuarez:oneltico:0.1.2')
  compile("org.springframework:spring-jms")
  compile("org.apache.activemq:activemq-broker")
  compile 'org.apache.activemq:activemq-pool'    
  compile 'org.springframework.cloud:spring-cloud-starter-eureka'
  compile 'com.mashape.unirest:unirest-java:1.4.9'      
  runtime "org.postgresql:postgresql:9.4-1203-jdbc42"
  testCompile('org.springframework.boot:spring-boot-starter-test')
}

eclipse {
  classpath {
    containers.remove('org.eclipse.jdt.launching.JRE_CONTAINER')
    containers 'org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8'
  }
}

springBoot {
  executable = true
}

我取出插件,它可以正确执行。

我知道这应该是Windows长路径问题,但我该如何给出解决方案?

最佳答案

tim_yates 是对的,谢谢!

我从链接中获取代码并将其粘贴到我的 build.gradle 文件的末尾,它就像一个 gem 一样工作!

我添加的代码是:

task pathingJar(type: Jar) {
    dependsOn configurations.runtime
    appendix = 'pathing'

    doFirst {
        manifest {
            attributes "Class-Path": configurations.runtime.files.collect {
                it.toURL().toString().replaceFirst('/file:/+/', '/')
                }.join(' ')
        }
    }
}

bootRun {
    dependsOn pathingJar
    doFirst {
        classpath = files("$buildDir/classes/main", "$buildDir/resources/main", pathingJar.archivePath)
    }
}

注意:我从链接代码中添加了一些简单的引号 (') 以使其正常工作..

关于gradle - gradle bootRun 执行失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39756475/

相关文章:

java - osgi.wiring.package; (&(osgi.wiring.package = org.json)(版本> = 0.0.0)) Unresolved 要求:

scala - 在IntelliJ中导入基于Gradle的Scala构建失败

java - Java webapp 中的 Groovy Web 控制台?

spring-boot - JBAS015852 : Could not index class module-info. 类 - Spring Boot + Jboss 7.1.1

java - Spring Boot调用rest ws SocketTimeoutException连接超时

android - 如何增加 Gradle 守护程序的最大堆大小?

java -> 无法创建监听器 : formatters {[com. puppycrawl.tools.checkstyle.ant.CheckstyleAntTask$Formatter@1326df32

java - 在失控的 GroovyShell 服务器线程上调用 Thread.stop 是否风险太大?

java - Groovy 空格分隔的 HashMap 键

java - Spring Boot @Autowired 在运行时创建实例