我正在将一个maven项目迁移到STS中的gradle。
我的pom.xml是:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.myPack</groupId>
<artifactId>sdk-devproxy</artifactId>
<version>0.0.1-RELEASE</version>
<packaging>jar</packaging>
<name>sdk-devproxy</name>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.10.RELEASE</version>
<type>pom</type>
<scope>import</scope>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-parent</artifactId>
<version>Edgware.SR3</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-oauth2</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-zuul</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-log4j</artifactId>
<version>1.3.8.RELEASE</version>
</dependency>
<!-- https://mvnrepository.com/artifact/com.auth0/java-jwt -->
<dependency>
<groupId>com.auth0</groupId>
<artifactId>java-jwt</artifactId>
<version>3.3.0</version>
</dependency>
</dependencies>
<build>
<finalName>sdk-devproxy</finalName>
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
</resource>
</resources>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<version>2.7</version>
</plugin>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<mainClass>com.myPack.devproxy.DevProxyApp</mainClass>
</configuration>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>3.1.0</version>
</plugin>
</plugins>
</build>
</project>我已经使用自动maven来进行分级转换命令"gardle init“,我得到了下面的build.gradle。
apply plugin: 'java'
apply plugin: 'maven'
group = 'com.myPack'
version = '0.0.1-RELEASE'
description = """sdk-devproxy"""
sourceCompatibility = 1.8
targetCompatibility = 1.8
repositories {
maven { url "http://repo.maven.apache.org/maven2" }
}
dependencies {
compile group: 'org.springframework.cloud', name: 'spring-cloud-starter-oauth2', version:'1.2.2.RELEASE'
compile group: 'org.springframework.cloud', name: 'spring-cloud-starter-zuul', version:'1.4.4.RELEASE'
compile group: 'org.springframework.boot', name: 'spring-boot-starter-web', version:'1.5.10.RELEASE'
compile group: 'org.springframework.boot', name: 'spring-boot-starter-log4j', version:'1.3.8.RELEASE'
compile group: 'com.auth0', name: 'java-jwt', version:'3.3.0'
}对于这个构建是成功的,但是当我作为spring引导应用运行时,它提供了
Error: Could not find or load main class com.myPack.mindsphere.devproxy.DevProxyApp我尝试过更新、重建、更新分级项目等。我还指定了主要类名如下:
jar {
manifest {
attributes(
'Class-Path': configurations.compile.collect { it.getName() }.join(' '),
'Main-Class': 'com.myPack.mindsphere.devproxy.DevProxyApp'
)
}
}可能会有什么问题:
发布于 2018-05-29 06:17:18
你试过使用:
./gradlew bootRepackage或./gradlew bootJar./gradlew bootRun描述为
https://docs.spring.io/spring-boot/docs/2.0.2.RELEASE/gradle-plugin/reference/html/
如果您使用的是gradle版本,Gradle 3.4或更高版本,根据最新的文档https://spring.io/blog/2017/04/05/spring-boot-s-new-gradle-plugin,它使用bootJar任务代替bootRepackage
用于构建可执行jars和wars的bootRepackage任务已分别替换为bootJar和bootWar任务。这两个任务都扩展了它们等效的标准Gradle jar或war任务,允许您访问所有常见的配置选项和行为。
应用程序的运行配置:
build.gradle
apply plugin: 'java'
apply plugin: 'maven'
//apply plugin: 'io.spring.dependency-management'
group = 'com.myPack'
version = '0.0.1-RELEASE'
description = """sdk-devproxy"""
sourceCompatibility = 1.8
targetCompatibility = 1.8
buildscript {
ext {
springBootVersion = '2.0.1.RELEASE'
}
repositories {
mavenCentral()
}
dependencies {
classpath(
"org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
}
}
apply plugin: 'org.springframework.boot'
repositories {
maven { url "http://repo.maven.apache.org/maven2" }
}
dependencies {
compile group: 'org.springframework.cloud', name: 'spring-cloud-starter-oauth2', version:'1.2.2.RELEASE'
compile group: 'org.springframework.cloud', name: 'spring-cloud-starter-zuul', version:'1.4.4.RELEASE'
compile group: 'org.springframework.boot', name: 'spring-boot-starter-web', version:'1.5.10.RELEASE'
//compile group: 'org.springframework.boot', name: 'spring-boot-starter-log4j', version:'1.3.8.RELEASE'
compile group: 'com.auth0', name: 'java-jwt', version:'3.3.0'
}
bootJar {
mainClassName = 'com.myPack.mindsphere.devproy.DevProxyApp'
}https://stackoverflow.com/questions/50577412
复制相似问题