Advertisement
Advertisement

More Related Content

Advertisement

Write Gradle Plugins

  1. WRITE GRADLE PLUGINSWRITE GRADLE PLUGINS ESCRIBIR Y PUBLICAR TUS PLUGINS DEESCRIBIR Y PUBLICAR TUS PLUGINS DE GRADLE "MADE EASY"GRADLE "MADE EASY" Jorge Aguilera 1
  2. PRESENTACIÓNPRESENTACIÓN Created by /Jorge Aguilera @jagedn 2
  3. PRESENTACIÓNPRESENTACIÓN @jagedn (Jorge Aguilera) Created by /Jorge Aguilera @jagedn 2
  4. PRESENTACIÓNPRESENTACIÓN @jagedn (Jorge Aguilera) Groovy (101 GroovyScript) Created by /Jorge Aguilera @jagedn 2
  5. PRESENTACIÓNPRESENTACIÓN @jagedn (Jorge Aguilera) Groovy (101 GroovyScript) Groogle (Groovy+Google) Created by /Jorge Aguilera @jagedn 2
  6. PRESENTACIÓNPRESENTACIÓN @jagedn (Jorge Aguilera) Groovy (101 GroovyScript) Groogle (Groovy+Google) Extensiones de Asciidoctor (Puravida Extensions) Created by /Jorge Aguilera @jagedn 2
  7. PRESENTACIÓNPRESENTACIÓN @jagedn (Jorge Aguilera) Groovy (101 GroovyScript) Groogle (Groovy+Google) Extensiones de Asciidoctor (Puravida Extensions) Gradle Plugins Created by /Jorge Aguilera @jagedn 2
  8. PRESENTACIÓNPRESENTACIÓN @jagedn (Jorge Aguilera) Groovy (101 GroovyScript) Groogle (Groovy+Google) Extensiones de Asciidoctor (Puravida Extensions) Gradle Plugins Disclaimer Created by /Jorge Aguilera @jagedn 2
  9. PARTICIPAPARTICIPA 3
  10. AGENDAAGENDA 4
  11. AGENDAAGENDA Introducción a Gradle 4
  12. AGENDAAGENDA Introducción a Gradle Project, tasks, plugins 4
  13. AGENDAAGENDA Introducción a Gradle Project, tasks, plugins Pasos para construir y publicar en Gradle 4
  14. AGENDAAGENDA Introducción a Gradle Project, tasks, plugins Pasos para construir y publicar en Gradle Demo time 4
  15. AGENDAAGENDA Introducción a Gradle Project, tasks, plugins Pasos para construir y publicar en Gradle Demo time PuraVida Gradle plugins 4
  16. 5
  17. GRADLEGRADLE Gradle vs Maven vs Ant Install download & unzip sdkman install gradle docker run -v $(pwd):/home/gradle/gradle gradle init ./gradlew [-b build.gradle] hello 6
  18. CONCEPTOSCONCEPTOS Project(s) Task(s) Plugin(s) 7
  19. PROJECTPROJECT Cada build de Gradle está formado por un conjunto de proyectos. Puede ser construir un algo (un jar, un war, un zip, etc) Pero también puede ser hacer algo (desplegar un servicio, enviar un tweet, etc) 8
  20. TIPSTIPS build.gradle es un DSL (ver charla de Groogle) que describe builds es Groovy!!! Lo que no está de nido en build.gradle se busca en Project 9
  21. PROJECT PROPERTIESPROJECT PROPERTIES Name Type Default project Project The Project instance name String The name of the project directory. path String The absolute path of the project. description String A description for the project. projectDir File The directory containing the build script. 10
  22. PROJECT PROPERTIESPROJECT PROPERTIES Name Type Default buildDir File projectDir/build group Object unspecified version Object unspecified ant AntBuilder An AntBuilder instance 11
  23. TASKTASK Unidad básica de los proyectos. 12
  24. TASK 1/3TASK 1/3 gradle hello task hello(){ doLast{ println "hello" } } 13
  25. TASK 2/3TASK 2/3 gradle goodbye task hello(){ doLast{ println "hello" } } task goodbye(){ doLast{ println "goodbye" } } goodbye.dependsOn hello 14
  26. TASK 3/3TASK 3/3 gradle hello task hello(){ doLast{ println "hello ISS" } } hello.onlyIf{ def json = new groovy.json.JsonSlurper(). parseText("http://api.open-notify.org/iss-now.json".toURL float nlon = json.iss_position.longitude as float float nlat = json.iss_position.latitude as float float LAT = 40.4237401 float LON = -3.7012653 Math.abs(LAT-nlat) < 1 && Math.abs(LON-nlon) < 1 } 15
  27. 16
  28. PLUGINSPLUGINS Mecanismo para compartir Tasks Un plugin puede añadir 1 o varias Tasks Dónde: chero build.gradle directorio buildSrc/src/main/groovy proyecto independiente 17
  29. BUILD.GRADLE / BUILDSRCBUILD.GRADLE / BUILDSRC class GreetingPlugin implements Plugin<Project> { void apply(Project project) { project.task('hello') { doLast { println 'Hello from the GreetingPlugin' } } } } apply plugin: GreetingPlugin 18
  30. PROYECTO INDEPENDIENTEPROYECTO INDEPENDIENTE Elegir un nombre cuali cado gradle init Crear MyTask Crear MyPlugin y aplicar la Task Anotar con @TaskAction el main de la Task Declarar el plugin /META-INF/gradle- plugins/TU.PLUGIN.CUALIFICADO.properties 19
  31. DEPENDENCIASDEPENDENCIAS dependencies { compile localGroovy() compile gradleApi() } 20
  32. DECLARAR EL PLUGINDECLARAR EL PLUGIN TU.PLUGIN.CUALIFICADO.properties implementation-class=com.foo.baar.MyPlugin 21
  33. PLUGINPLUGIN class MyPlugin implements Plugin<Project> { void apply(Project project) { project.with { apply(plugin: 'base') task('mytask', type:MyTask, group:'others', description: 'Look Mom, a plugin from Puravida in } } } } 22
  34. TASKTASK class MyTask extends DefaultTask{ @TaskAction void callYourMethodAsYouWant(){ println "Hello" } } 23
  35. CONFIGURACIÓN TASKCONFIGURACIÓN TASK 24
  36. CONFIGURACIÓN TASKCONFIGURACIÓN TASK Identi car propiedades de la task 24
  37. CONFIGURACIÓN TASKCONFIGURACIÓN TASK Identi car propiedades de la task Aunque sea Groovy crea métodos get/set más una función 24
  38. CONFIGURACIÓN TASKCONFIGURACIÓN TASK Identi car propiedades de la task Aunque sea Groovy crea métodos get/set más una función Piensa en el usuario y no te limites a una lista de propiedades (puedes anidarlas) 24
  39. CONFIGURACIÓN TASKCONFIGURACIÓN TASK Identi car propiedades de la task Aunque sea Groovy crea métodos get/set más una función Piensa en el usuario y no te limites a una lista de propiedades (puedes anidarlas) Input (un chero de entrada por ejemplo) vs Output (un directorio de salida) 24
  40. CONFIGURACIÓN TASKCONFIGURACIÓN TASK Identi car propiedades de la task Aunque sea Groovy crea métodos get/set más una función Piensa en el usuario y no te limites a una lista de propiedades (puedes anidarlas) Input (un chero de entrada por ejemplo) vs Output (un directorio de salida) Valores simples, basados en cheros ( le, collections, etc), anidadas 24
  41. ANOTACIONESANOTACIONES Anota siempre métodos get o la property Groovy para ayudar a Gradle!! Name Name Name Name @Input @Output @InputFile @OutputFile @InputFiles @OutputFiles @InputDirectory @OutputDirectory @Optional @Internal @Nested @TaskAction 25
  42. TESTTEST Podemos utilizar JUnit y/o Spock para crear tests!! plugins { id 'java-gradle-plugin' } dependencies{ // add these testCompile gradleTestKit() testCompile group: 'junit', name: 'junit', version: '4.12' testCompile ("org.spockframework:spock-core:1.1-groovy-2.4") exclude group: 'org.codehaus.groovy', module: 'groovy-all exclude group: 'org.hamcrest', module: 'hamcrest-core' } } 26
  43. MYTASKSPECMYTASKSPEC class MyTaskSpec extends Specification{ @Rule TemporaryFolder testProjectDir File buildFile def setup() { buildFile = testProjectDir.newFile('build.gradle') buildFile << """ plugins { id 'TU.PLUGIN.CUALIFICADO' }""" } def "run task"() { buildFile << 'hello{}' when: def result = GradleRunner.create()....build() then: 27
  44. PUBLISHPUBLISH plugins{ id "com.gradle.plugin-publish" version "0.10.0" } ./gradlew publishPlugins 28
  45. DEMO PARTYDEMO PARTY Download NASA images 29
  46. PURAVIDA GRADLE PLUGINSPURAVIDA GRADLE PLUGINS 30
  47. PURAVIDA GRADLE PLUGINSPURAVIDA GRADLE PLUGINS Funcionales 30
  48. PURAVIDA GRADLE PLUGINSPURAVIDA GRADLE PLUGINS Funcionales Didácticos 30
  49. CHECK-SERVERCHECK-SERVER Ejecuta la task si una URL devuelve 200 y puedes descargar el body a chero id 'com.puravida.gradle.checkserver' Show me the code!!! https://puravida-gradle.gitlab.io/check-server 31
  50. SOCIAL NETWORKSOCIAL NETWORK Comparte el resultado de un build por ejemplo twitter, telegram, slack id 'com.puravida.gradle.socialnetwork' Show me the code!!! https://puravida-gradle.gitlab.io/social-network 32
  51. GROOGLEGROOGLE Descarga/Sube cheros de/a tu Drive (por ahora) id 'com.puravida.gradle.groogle' Show me the code!!! https://puravida-gradle.gitlab.io/groogle 33
  52. 34
Advertisement