2016-11-28 42 views
1

我收到以下錯誤,而在CI環境無主清單屬性,在application.jar

java -jar application.jar 

no main manifest attribute, in application.jar 

奇怪的是春天開機罐子,它並沒有給這個問題在我的本地或詹金斯奴隸。它開始好了。

當我將jar上傳到Nexus artifactory並將其下載到我的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. Gradle- no main manifest attribute 2. http://www.vogella.com/tutorials/Gradle/article.html#specifying-the-java-version-in-your-build-file 3. Can't execute jar- file: "no main manifest attribute"

+0

不相關,但你應該使用「提供的org.projectlombok:lombok:1.16.14」,而不是編譯 – yelliver

回答

-1

它曾與

gradle upload -x jar 
+0

沒有爲我工作(今天,多年後,與gradle 4.2.1):「任務'上傳'找不到根項目」 – Henning

+0

它適用於我發佈的問題。我上傳的是uploadArchives –

0

默認打包諮詢大廈罐子jar文件不包含MANIFEST文件。 我不知道如何在搖籃配置,但在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> 

而且它爲我工作。 您可以將Maven插件配置更改爲Gradle。

+0

感謝您的答案。任何鏈接/教程從我可以讀取相同的地方? –

0

我不得不跑gradle bootRepackage建立jar和git後,我可以執行一個jar!