Generate jar for source code using Gradle

297 views Asked by At

I'm trying to generate the jar file for the source code of a Gradle project. I'm using Gradle 6.6.1 I tried

task fatJar2(type: Jar) {
  manifest {
    attributes 'Main-Class': 'com.main.MainClass'
  }
  archiveClassifier = "all"
  from {
    configurations.compile.collect { it.isDirectory() ? it : zipTree(it) }
    configurations.runtimeClasspath.collect { it.isDirectory() ? it : zipTree(it) }
    }
  with jar
}

it's giving me the following error:

C:\api_test_restassured_nickt>gradle :fatJar2 > Task :compileJava FAILED ^ Note: Some input files use unchecked or unsafe operations. Note: Recompile with -Xlint:unchecked for details. 100 errors FAILURE: Build failed with an exception. * What went wrong: Execution failed for task ':compileJava'. > Compilation failed; see the compiler error output for details. BUILD FAILED in 2s 1 actionable task: 1 executed 

It's way too long. But it shows a list of packages that all pertain to another repo (framework). The test repo for which i'm trying to build the JAR is dependent on the Framework.

Below is my build.gradle class

/*
 * This build file was auto generated by running the Gradle 'init' task
 * at '1/28/16 10:33 AM' with Gradle 2.9
 *
 * This generated file contains a sample Java project to get you started.
 * For more details take a look at the Java Quickstart chapter in the Gradle
 * user guide available at https://docs.gradle.org/2.9/userguide/tutorial_java_projects.html
 */

apply plugin: 'java'

sourceCompatibility = 8

targetCompatibility = 8



task fatJar(type: Jar) {

    manifest {

        attributes 'tests': 'Gradle Jar'
    }
    
      from {
        configurations.compile.collect { it.isDirectory() ? it : zipTree(it) }
    }

    baseName = project.name

    with jar

}

task fatJar2(type: Jar) {
  manifest {
    attributes 'Main-Class': 'com.main.MainClass'
  }
  archiveClassifier = "all"
  from {
    configurations.compile.collect { it.isDirectory() ? it : zipTree(it) }
    configurations.runtimeClasspath.collect { it.isDirectory() ? it : zipTree(it) }
    }
  with jar
}

repositories {

    jcenter()

    mavenCentral()

    flatDir {

       dirs 'libs'

   }

}

task copyDependencies(type: Copy) {
   from configurations.compile   
   into 'dependenciesTestRepo'
}

dependencies {

    compile 'org.testng:testng:6.9.10'

    compile group: 'com.jayway.restassured', name: 'rest-assured', version:'2.9.0'
    
    compile group: 'com.opencsv', name: 'opencsv', version: '5.2'

    implementation "javax.xml.bind:jaxb-api:2.2.11"

    implementation "com.sun.xml.bind:jaxb-core:2.2.11"

    implementation "com.sun.xml.bind:jaxb-impl:2.2.11"

    implementation "javax.activation:activation:1.1.1" 

}

If i Export to Jar File using Eclipse, it works perfectly. So basically, what i need to do is do the Export to JAR functionality that Eclipse has but in Command Line. Any ideas on how can i generate this jar file?

0

There are 0 answers