Java application.jar中没有主清单属性
在CI环境中使用spring引导jar时,我遇到以下错误Java application.jar中没有主清单属性,java,gradle,spring-boot,nexus,Java,Gradle,Spring Boot,Nexus,在CI环境中使用spring引导jar时,我遇到以下错误 java -jar application.jar no main manifest attribute, in application.jar 奇怪的是,它没有给我的本地或詹金斯奴隶的问题。一开始就不错 当我将jar上传到nexusartifactory并将其下载到我的CI环境中时,它面临着一个问题 使用 gradle clean build -x test 我的gradle.build文件 buildscript { r
java -jar application.jar
no main manifest attribute, in application.jar
奇怪的是,它没有给我的本地或詹金斯奴隶的问题。一开始就不错
当我将jar上传到nexusartifactory并将其下载到我的CI环境中时,它面临着一个问题
使用
gradle clean build -x test
我的gradle.build文件
buildscript {
repositories {
maven {
url "https://plugins.gradle.org/m2/"
}
jcenter()
mavenLocal()
mavenCentral()
}
dependencies {
classpath 'org.akhikhl.gretty:gretty:1.2.4'
classpath 'org.ajoberstar:gradle-jacoco:0.1.0'
classpath 'org.sonarsource.scanner.gradle:sonarqube-gradle-plugin:1.2'
classpath("org.springframework.boot:spring-boot-gradle-plugin:1.3.6.RELEASE")
}
}
repositories {
mavenCentral()
mavenLocal()
maven {
credentials {
username "hello"
password "world"
}
url "Nexus URL"
}
}
apply plugin: 'maven-publish'
apply plugin: 'java'
apply plugin: 'maven'
apply plugin: 'spring-boot'
apply plugin: "org.sonarqube"
apply plugin: 'jacoco'
group = 'com.company.pod'
/* Determining version from jenkins pipeline, otherwise is set to 1.0.0-SNAPSHOT */
version = new ProjectVersion(1, 0, System.env.SOURCE_BUILD_NUMBER, System.env.RELEASE_TYPE)
println(version)
class ProjectVersion {
Integer major
Integer minor
String build
String releaseType
ProjectVersion(Integer major, Integer minor, String build, String releaseType) {
this.major = major
this.minor = minor
this.build = build
this.releaseType = releaseType
}
@Override
String toString() {
String fullVersion = "$major.$minor"
if(build) {
fullVersion += ".$build"
}
else{
fullVersion += ".0"
}
if(releaseType) {
fullVersion += "-RELEASE"
}
else{
fullVersion += "-SNAPSHOT"
}
fullVersion
}
}
/*Sonarqube linting of your repository.*/
sonarqube {
properties {
property "sonar.language", "java"
}
}
/* Please don't comment out the part below
To run the same on your laptops/prod boxes/CUAT boxes, just edit the gradle.properties file.
(It will be present in the home directory of the user you are using to run gradle with.`sudo` means root user and likewise)
Enter the following lines(and yes, it will run without values, thank you gradle!)
nexusUrl=
nexusRelease=
nexusSnapshot=
nexusUsername=
nexusPassword=
*/
uploadArchives {
repositories {
mavenDeployer {
repository(url: nexusUrl+"/"+nexusRelease+"/") {
authentication(userName: nexusUsername, password: nexusPassword)
}
snapshotRepository(url: nexusUrl+"/"+nexusSnapshot+"/"){
authentication(userName: nexusUsername, password: nexusPassword)
uniqueVersion = false
}
}
}
}
publishing {
publications {
mavenJava(MavenPublication) {
from components.java
}
}
}
publishing {
publications {
maven(MavenPublication) {
groupId 'com.company.something'/*This is different from group variable before*/
artifactId 'something'
version '2.0.0'
from components.java
}
}
}
/*
publishing {
repositories {
maven {
url "~/.m2/repository/"
}
}
}
*/
task wrapper(type: Wrapper) {
gradleVersion = '2.9'
distributionUrl = "https://services.gradle.org/distributions/gradle-$GradleVersion-all.zip"
}
dependencies {
compile('org.projectlombok:lombok:1.16.6')
compile("com.company.commons:company-app:0.0.1-RELEASE")
compile group: 'com.google.guava', name: 'guava', version: '19.0'
compile("com.squareup.retrofit2:retrofit:2.0.1")
compile("com.squareup.retrofit2:converter-jackson:2.0.1")
compile("org.springframework.boot:spring-boot-starter-data-jpa")
compile group: 'ch.qos.logback', name: 'logback-classic', version: '1.1.7'
compile("com.getsentry.raven:raven-logback:7.2.2")
compile("org.springframework.boot:spring-boot-starter-actuator")
testCompile("org.springframework.boot:spring-boot-starter-test")
testCompile("com.h2database:h2")
testCompile("junit:junit")
// testCompile("org.springframework.boot:spring-boot-starter-test")
// testCompile group: 'org.hibernate', name: 'hibernate-validator', version: '4.2.0.Final'
}
征询的文章没有白费
1.
2.
3. 默认打包的jar文件不包含清单文件。 我不知道如何在Gradle中配置,但在Maven中添加插件时:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
<configuration>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<mainClass>vn.dung.Application</mainClass>
</manifest>
</archive>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
<appendAssemblyId>false</appendAssemblyId>
</configuration>
</plugin>
org.apache.maven.plugins
maven汇编插件
包裹
单一的
真的
vn.dung.Application
带有依赖项的jar
假的
这对我很有用。
您可以将Maven插件配置更改为Gradle。嗨,我遇到了完全相同的问题,我在以下内容中找到了答案: 我使用了解决方案2
publish {
dependsOn assemble
}
它与
gradle upload -x jar
在构建了jar之后,我必须运行
gradlebootrepackage
,然后git一个我可以执行的jar 在build.gradle中,我注意到启动重新打包被禁用,所以我启用了它:
bootRepackage {
enabled = true
}
谢谢你的回答。任何我可以阅读的链接/教程?不相关,但你应该使用“提供的org.projectlombok:lombok:1.16.14”,不编译不适用于我(多年后的今天,gradle 4.2.1):“在根项目中找不到任务‘上传’”它适用于我发布的问题。我的上传是UploadArchives这两个选项都不适用于我,只会导致错误。