Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Include sources in aar relase package #25

Closed
levibostian opened this issue Nov 27, 2018 · 2 comments
Closed

Include sources in aar relase package #25

levibostian opened this issue Nov 27, 2018 · 2 comments

Comments

@levibostian
Copy link
Owner

I want to package the source code .jar with the Teller package so that users of the library can browse the source inside of Android Studio.

After some research, I am still not quite sure how to do this. However, from this SO question, I have an idea of the configuration to use. I have used this configuration in the past before, but I had no luck. I believe that is because of one of the comments someone mentioned, "it works for tagged releases for us". I did not tag a release.

In the teller/build.gradle file, include this code at the base of the file:

task sourcesJar(type: Jar, dependsOn: classes) {
    classifier = 'sources'
    from sourceSets.main.allSource
}

task javadocJar(type: Jar, dependsOn: javadoc) {
    classifier = 'javadoc'
    from javadoc.destinationDir
}

artifacts {
    archives sourcesJar
    archives javadocJar
}

I learned, also from that SO question, on how to view the directory of built artifacts for JitPack. Go to this link and it shows all the index of the tagged releases for that project. Append a tagged release to the URL of the browser to view the contents of that release. You will notice for 0.0.1 release of Teller, you do not see a -sources.jar resource.

@levibostian
Copy link
Owner Author

This was attempted in this pr. After the next release, we will see if it worked or not.

@levibostian levibostian changed the title Include sources into jitpack resource Include sources in aar relase package Feb 25, 2019
@levibostian
Copy link
Owner Author

This has been resolved!

I am using Kotlin and Dokka. With that in mind, here is my configuration code used to generate sources and javadoc jar files:

apply plugin: 'org.jetbrains.dokka-android'

task sourcesJar(type: Jar) {
    classifier = 'sources'
    from android.sourceSets.main.java.srcDirs 
}

task javadocJar(type: Jar, dependsOn: dokkaJavadoc) {
    classifier = 'javadoc'
    from "$buildDir/javadoc"
}

artifacts {
    archives sourcesJar
    archives javadocJar
}

When you now run ./gradlew install, you should see javadoc files being generated in teller-android/build/javadoc. Then, the 2 jar files should be located in teller-android/build/libs/. Just to be sure everything worked correctly, unzip the .jar files and view the inside files to make sure that sources.jar actually contains source code and not just directories.

Then, when the code is uploaded to jCenter (have not tested with Jitpack), then the sources should be downloaded and shown inside of Android Studio. If not, delete your ~/.gradle/caches directory and re-open your Android Studio project where it will redownload dependencies.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant