🗒️
notes
  • Journal
  • URLs
  • Java Card
    • SCP02
    • Rapid Notes
    • _FIXVALS_
    • Mifare
    • Chain Of Trust
  • Encoding
    • CBEFF
    • Bytes
  • Snippets
    • JNI_OnLoad
  • float to byte[]
  • Protobuf
  • C/C++
    • Containers
    • Basics
    • JNI
    • gcov
    • Castings
  • chess
    • Untitled
  • Compression
    • Untitled
  • Snippets
    • Untitled
  • Build Systems
    • Maven
    • Windows
  • Gradle
  • CMake
  • Java
    • Untitled
    • Certificates
  • Android
    • Mifare
  • Python
    • ctypes
  • WebSub
    • References
  • Spring Boot
    • Form-based Authentication
    • Basic Access Authentication
    • JWT Authentication
  • QR Code
    • Denso QR Code
  • Philosophical Inquiry
    • First
  • XML
    • xmlstarlet
Powered by GitBook
On this page

Was this helpful?

Gradle

In NixOS, nix-shell -p gradle is enough.

A gradle script handle two things:

  • projects

  • tasks

gradle -q hello :

// build.gradle

task hello {
   doLast {
      println "tutorialspoint [${project}]"
      println "[${path}]"
      println "[${projectDir}]"
      println "[${buildDir}]"
   }
}

task upper {
   doLast {
       String expString = 'TUTORIALS point'
       println "Original: " + expString
       println "Upper case: " + expString.toUpperCase()
   }
}

// Take note it is plural tasks
tasks.create(name: 'abc') {
    doLast {
        println("*** abc ***")
    }
}

Task phases:

  • configuration phase

  • execution phase (doFirst, doLast)

---------------------------------------------------------------------------------------------------------------

Sample ok build.gradle :

apply plugin: 'java'

repositories {
   mavenCentral()
   google()
   jcenter()
}

dependencies {
   compile group: 'com.google.protobuf', name: 'protobuf-java', version: '3.12.2'
   compile group: 'com.google.zxing', name: 'core', version: '3.4.0'
   compile group: 'com.google.zxing', name: 'javase', version: '3.4.0'
   compile group: 'net.java.dev.jna', name: 'jna', version: '5.5.0'
   compile group: 'com.goterl.lazycode', name: 'lazysodium-java', version: '4.2.5'
   compile group: 'co.libly', name: 'resource-loader', version: '1.3.7'
   compile group: 'at.favre.lib', name: 'bytes', version: '1.3.0'
}

task AAA {
    println("-- AAA --")
    doLast {
        println("** AAA **")
    }
}
mkdir -p src/main/java
touch src/main/java/App.java
gradle build

Without any java source file, gradle build won't download the jars.

How to reference a local jar within build.gradle:

apply plugin: 'java'

repositories {
   mavenCentral()
   google()
   jcenter()

   flatDir {
      dirs rootDir.absolutePath + '/projectA/src/main/java/proto'
   }
}

dependencies {
   compile group: 'com.google.protobuf', name: 'protobuf-java', version: '3.12.2'
   compile group: 'com.google.zxing', name: 'core', version: '3.4.0'
   compile group: 'com.google.zxing', name: 'javase', version: '3.4.0'
   compile group: 'net.java.dev.jna', name: 'jna', version: '5.5.0'
   compile group: 'com.goterl.lazycode', name: 'lazysodium-java', version: '4.2.5'
   compile group: 'co.libly', name: 'resource-loader', version: '1.3.7'
   compile group: 'at.favre.lib', name: 'bytes', version: '1.3.0'

   // either of these 3 works!
   //compile name: 'card_access.proto'
   //compile fileTree(dir: idpass_proto, include: '*.jar')
   implementation files('src/main/java/proto/card_access.proto.jar')
}

To create gradle wrapper:

gradle wrapper --gradle-version 5.6.1

These two are the same:

dependencies {
  /* THIS
  compile group: 'com.google.protobuf', name: 'protobuf-java', version: '3.12.2'
  compile group: 'com.google.zxing', name: 'core', version: '3.4.0'
  compile group: 'com.google.zxing', name: 'javase', version: '3.4.0'
  compile group: 'net.java.dev.jna', name: 'jna', version: '5.5.0'
  compile group: 'com.goterl.lazycode', name: 'lazysodium-java', version: '4.2.5'
  compile group: 'co.libly', name: 'resource-loader', version: '1.3.7'
  compile group: 'at.favre.lib', name: 'bytes', version: '1.3.0'
  */
  
  // or THIS
  implementation 'com.google.protobuf:protobuf-java:3.12.2'
  implementation 'com.google.zxing:core:3.4.0'
  implementation 'com.google.zxing:javase:3.4.0'
  implementation 'net.java.dev.jna:jna:5.5.0'
  implementation 'com.goterl.lazycode:lazysodium-java:4.2.5'
  implementation 'co.libly:resource-loader:1.3.7'
  implementation 'at.favre.lib:bytes:1.3.0'
}

Gradle File API

task copyPoems(type: Copy) {
  from 'text-files'
  into 'build/poems'
}

task copyjar(type: Copy) {
  from 'text-files/test.jpg'
  into 'c:/Users/63927/cooljars'
}

Control Name of Jar in Gradle

In build.gradle

task buildjar(type: Jar) {
    archiveBaseName = 'desired-name-here'
}

But you have to invoke the task manually such as: gradle buildjar for the task to run.

Know, that this can also be controlled in settings.gradle as:

rootProject.name = 'desired-name-here'
PreviousWindowsNextCMake

Last updated 4 years ago

Was this helpful?