Slide 1

Slide 1 text

Library development: open source your ideas DEVFEST MILANO 2018 6th October 2018

Slide 2

Slide 2 text

MARCO GOMIERO - Computer Engineer (Almost) - Android Engineer @ Uniwhere - Co-Leader @ GDG Venezia WHO WE ARE ANDREA MAGLIE FOLLOW ME: ● twitter.com/marcoGomier ● github.com/prof18 ● [email protected] ● marcogomiero.com - Computer Engineer - Software Engineer @ Musement - Founder @ GDG Venezia FOLLOW ME: ● twitter.com/TechIsFun ● github.com/TechIsFun ● [email protected] ● andreamaglie.com

Slide 3

Slide 3 text

AGENDA 1. Why ? 2. How to publish code and make it “open” 3. How to check code quality 4. How to publish artifacts 5. How to choose a license

Slide 4

Slide 4 text

DISCLAIMER: all it’s based on our experience

Slide 5

Slide 5 text

How about you?

Slide 6

Slide 6 text

Library? Open source? Why?

Slide 7

Slide 7 text

Contribute and help the community

Slide 8

Slide 8 text

Divide and conquer

Slide 9

Slide 9 text

Gain coding experience

Slide 10

Slide 10 text

Build reputation (also for your CV)

Slide 11

Slide 11 text

How?

Slide 12

Slide 12 text

RSS Parser

Slide 13

Slide 13 text

RSS Parser

Slide 14

Slide 14 text

THE EASY WAY

Slide 15

Slide 15 text

● GITHUB ● TRAVIS CI ● JITPACK

Slide 16

Slide 16 text

● GITHUB

Slide 17

Slide 17 text

1. Start a new project from GitHub 2. Push local project to GitHub 3. Fork a project

Slide 18

Slide 18 text

1. Start a new project from GitHub

Slide 19

Slide 19 text

1. Start a new project from GitHub

Slide 20

Slide 20 text

> git init > git add . > git commit -m "git setup" > git remote add origin > git push -u origin master 2. Push local project to GitHub

Slide 21

Slide 21 text

3. Fork a project

Slide 22

Slide 22 text

3. Fork a project

Slide 23

Slide 23 text

4. Pull Request

Slide 24

Slide 24 text

4. Pull Request

Slide 25

Slide 25 text

● TRAVIS CI

Slide 26

Slide 26 text

● https://travis-ci.org/ ● Free ● Easy to configure and manage

Slide 27

Slide 27 text

1. Login with Github 2. Enable repository

Slide 28

Slide 28 text

3. travis.yml (1) language: android android: components: - build-tools-27.0.3 - android-27 - add-on - extra script: - "./gradlew build"

Slide 29

Slide 29 text

> gem install travis > travis setup releases 3. travis.yml (2)

Slide 30

Slide 30 text

3. travis.yml (3) ... deploy: provider: releases api_key: secure: pEgyNmHdAexY2Vtjn file: rssparser/build/outputs/aar/rssparser-release.aar skip_cleanup: true on: repo: TechIsFun/RSS-Parser branch: master tags: true

Slide 31

Slide 31 text

No content

Slide 32

Slide 32 text

4. Badge

Slide 33

Slide 33 text

4. Badge

Slide 34

Slide 34 text

● JITPACK

Slide 35

Slide 35 text

● https://jitpack.io/ ● Free for public repos ● Works only for Java and Android libraries

Slide 36

Slide 36 text

Jitpack

Slide 37

Slide 37 text

Jitpack

Slide 38

Slide 38 text

Jitpack allprojects { repositories { ... maven { url 'https://jitpack.io' } } }

Slide 39

Slide 39 text

Jitpack dependencies { implementation 'com.github.techisfun:rss-parser:0.1' }

Slide 40

Slide 40 text

Jitpack [![](https://jitpack.io/v/techisfun/RSS-Parser.svg)] (https://jitpack.io/#techisfun/RSS-Parser)

Slide 41

Slide 41 text

● https://github.com/checkstyle/checkstyle ● tool for checking Java source code for adherence to a Code Standard or set of validation rules

Slide 42

Slide 42 text

build.gradle (1) apply plugin: 'checkstyle'

Slide 43

Slide 43 text

task checkstyle(type: Checkstyle) { configFile rootProject.file('checkstyle.xml') source 'src/main/java' ignoreFailures false showViolations true include '**/*.java' classpath = files() } build.gradle (2)

Slide 44

Slide 44 text

afterEvaluate { if (project.tasks.findByName('check')) { check.dependsOn('checkstyle') } } build.gradle (3)

Slide 45

Slide 45 text

./gradlew rssparser:checkstyle ./gradlew build Checkstyle

Slide 46

Slide 46 text

THE “TRICKIEST” WAY

Slide 47

Slide 47 text

THE “TRICKIEST” WAY OR BETTER ...

Slide 48

Slide 48 text

THE “COOLEST” WAY

Slide 49

Slide 49 text

dependencies { implementation 'com.github.User:Repo:Tag' } The easy way

Slide 50

Slide 50 text

com.github in front of my name?

Slide 51

Slide 51 text

● BINTRAY ● JCENTER

Slide 52

Slide 52 text

● https://bintray.com ● Free ● Publish, Store, Promote, and Distribute Software

Slide 53

Slide 53 text

● JCenter is a Maven repository hosted by Bintray ● Default Repository of Android Studio

Slide 54

Slide 54 text

Scenario Build the Library Upload to Bintray Sync to jcenter

Slide 55

Slide 55 text

Create a Bintray account

Slide 56

Slide 56 text

Select Maven

Slide 57

Slide 57 text

Add New Package

Slide 58

Slide 58 text

Add New Package

Slide 59

Slide 59 text

Library repo is ready

Slide 60

Slide 60 text

Project: build.gradle dependencies { classpath 'com.android.tools.build:gradle:3.1.4' classpath 'com.github.dcendents:android-maven-gradle-plugin:2.0' classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.8.0' }

Slide 61

Slide 61 text

Library module: publish.gradle (1) apply plugin: 'maven-publish' apply plugin: 'com.jfrog.bintray' version '1.4.4' group 'com.prof.rssparser'

Slide 62

Slide 62 text

Library module: publish.gradle (2) publishing { publications { Production(MavenPublication) { artifact("$buildDir/outputs/aar/rssparser-release.aar") { builtBy tasks.getByName("assembleRelease") } groupId artifactId 'rssparser' version this.version pom.withXml { def dependenciesNode = asNode().appendNode('dependencies') // Add the dependecies configurations.implementation.allDependencies.each { // Ensure dependencies such as fileTree are not included in the pom. if (it.name != 'unspecified') { def dependencyNode = dependenciesNode.appendNode('dependency') dependencyNode.appendNode('groupId', it.group) dependencyNode.appendNode('artifactId', it.name) dependencyNode.appendNode('version', it.version) } } } } } }

Slide 63

Slide 63 text

Library module: publish.gradle (3) bintray { user = properties.getProperty("bintray.user") key = properties.getProperty("bintray.apikey") publications = ['Production'] configurations = ['archives'] override = true pkg { repo = 'maven' name = 'RSS-Parser' description = "An Android library to parse RSS Feed" publicDownloadNumbers = true licenses = ['Apache-2.0'] vcsUrl = 'https://github.com/prof18/RSS-Parser.git' version { name = this.version desc = "Example ${this.version}" released = new Date() vcsTag = this.version } } }

Slide 64

Slide 64 text

bit.ly/publishgradle CODE ON:

Slide 65

Slide 65 text

apply plugin: 'com.android.library' android { compileSdkVersion 28 ... } dependencies { ... } apply from: 'publish.gradle' Library module: build.gradle

Slide 66

Slide 66 text

Compile the library ./gradlew clean build bintrayUpload --info

Slide 67

Slide 67 text

Publish the new version

Slide 68

Slide 68 text

Publish the new version

Slide 69

Slide 69 text

Add the library to jcenter

Slide 70

Slide 70 text

Request the publication on jcenter

Slide 71

Slide 71 text

The library finally is on jcenter!

Slide 72

Slide 72 text

The library finally is on jcenter!

Slide 73

Slide 73 text

dependencies { implementation 'com.prof.rssparser:rssparser:1.4.4' } Use the library

Slide 74

Slide 74 text

License?

Slide 75

Slide 75 text

MIT License “do anything you want with my code”

Slide 76

Slide 76 text

Apache License 2.0 “do anything you want” + “keep copyright”

Slide 77

Slide 77 text

GNU GPLv3 “do anything you want” + “keep copyright” + “keep GNU GPLv3 license”

Slide 78

Slide 78 text

Contributing? You don’t need to choose a license!

Slide 79

Slide 79 text

Help? https://choosealicense.com/

Slide 80

Slide 80 text

Q & A

Slide 81

Slide 81 text

DevFest Veneto 2018 It’s coming!! 24 Novembre @ Fabrica - Catena di Villorba - TV Call For Paper opening soon!

Slide 82

Slide 82 text

Android Developers Italia Android Developers Italia é la community italiana di sviluppatori Android su Slack! androiddevs.it

Slide 83

Slide 83 text

THANK YOU