Skip to content

Commit

Permalink
update build and publishing config
Browse files Browse the repository at this point in the history
  • Loading branch information
laenger committed Mar 22, 2018
1 parent 36c6731 commit 9521e09
Show file tree
Hide file tree
Showing 11 changed files with 154 additions and 74 deletions.
28 changes: 21 additions & 7 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
buildscript {
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.2.3'
classpath 'com.neenbedankt.gradle.plugins:android-apt:1.8'
classpath 'com.android.tools.build:gradle:3.1.0-rc03'
}
}

Expand All @@ -15,16 +15,30 @@ ext {
nexusUsername = getEnvOrProperty('NEXUS_USERNAME')
nexusPassword = getEnvOrProperty('NEXUS_PASSWORD')

compileSdkVersion = 25
buildToolsVersion = '25.0.0'
targetSdkVersion = 25
developers = [
[
id : 'laenger',
name : 'Christian Langer',
email: '[email protected]'
]
]
scm = [
connection : 'scm:git:[email protected]:laenger/ViewPagerBottomSheet.git',
developerConnection: 'scm:git:[email protected]:laenger/ViewPagerBottomSheet.git',
url : 'https://github.com/laenger/ViewPagerBottomSheet'
]

supportVersion = '25.1.0'
butterknifeVersion = '8.4.0'
compileSdkVersion = 27
buildToolsVersion = '27.0.3'
targetSdkVersion = 27

supportVersion = '27.1.0'
butterknifeVersion = '8.8.1'
}

allprojects {
repositories {
google()
jcenter()
maven { url "https://raw.github.com/laenger/maven-releases/master/releases" }
maven { url "https://raw.github.com/laenger/maven-releases/master/snapshots" }
Expand Down
14 changes: 7 additions & 7 deletions example/build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
apply plugin: 'com.android.application'
apply plugin: 'com.neenbedankt.android-apt'

android {
compileSdkVersion rootProject.compileSdkVersion
Expand All @@ -23,15 +22,16 @@ android {
}
}

lintOptions {
abortOnError false
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}

dependencies {
compile "com.android.support:design:${supportVersion}"
compile project(path: ':vpbs', configuration: 'debug')
implementation "com.android.support:design:${supportVersion}"
implementation project(':vpbs')

compile "com.jakewharton:butterknife:${butterknifeVersion}"
apt "com.jakewharton:butterknife-compiler:${butterknifeVersion}"
implementation "com.jakewharton:butterknife:${butterknifeVersion}"
annotationProcessor "com.jakewharton:butterknife-compiler:${butterknifeVersion}"
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package biz.laenger.android.vpbs.example.fragments;

import android.annotation.SuppressLint;
import android.app.Dialog;
import android.content.Context;
import android.support.annotation.NonNull;
import android.support.design.widget.TabLayout;
import android.support.v4.view.ViewPager;
import android.support.v7.widget.Toolbar;
Expand All @@ -21,6 +23,7 @@ public class DialogFragment extends ViewPagerBottomSheetDialogFragment {
@BindView(R.id.bottom_sheet_tabs) TabLayout bottomSheetTabLayout;
@BindView(R.id.bottom_sheet_viewpager) ViewPager bottomSheetViewPager;

@SuppressLint("RestrictedApi")
@Override
public void setupDialog(Dialog dialog, int style) {
super.setupDialog(dialog, style);
Expand All @@ -44,7 +47,7 @@ static class SimplePagerAdapter extends android.support.v4.view.PagerAdapter {

private final Context context;

public SimplePagerAdapter(Context context) {
SimplePagerAdapter(Context context) {
this.context = context;
}

Expand All @@ -59,19 +62,20 @@ public int getCount() {
}

@Override
public boolean isViewFromObject(View view, Object object) {
public boolean isViewFromObject(@NonNull View view, @NonNull Object object) {
return object == view;
}

@NonNull
@Override
public Object instantiateItem(ViewGroup container, int position) {
public Object instantiateItem(@NonNull ViewGroup container, int position) {
final View view = LayoutInflater.from(container.getContext()).inflate(R.layout.fragment_nested_scroll, container, false);
container.addView(view);
return view;
}

@Override
public void destroyItem(ViewGroup container, int position, Object object) {
public void destroyItem(@NonNull ViewGroup container, int position, @NonNull Object object) {
container.removeView((View) object);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package biz.laenger.android.vpbs.example.fragments;

import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
Expand All @@ -12,7 +13,7 @@
public class NestedScrollFragment extends Fragment {

@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
return inflater.inflate(R.layout.fragment_nested_scroll, container, false);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import android.content.Context;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v7.widget.LinearLayoutManager;
Expand All @@ -20,14 +21,14 @@ public class RecyclerFragment extends Fragment {
@BindView(R.id.recycler_view) RecyclerView recyclerView;

@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
final View view = inflater.inflate(R.layout.fragment_recycler, container, false);
ButterKnife.bind(this, view);
return view;
}

@Override
public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);

recyclerView.setLayoutManager(new LinearLayoutManager(getContext(), LinearLayoutManager.VERTICAL, true));
Expand All @@ -41,13 +42,14 @@ private SimpleAdapter(Context context) {
layoutInflater = LayoutInflater.from(context);
}

@NonNull
@Override
public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
return new ViewHolder((TextView) layoutInflater.inflate(R.layout.textview, parent, false));
}

@Override
public void onBindViewHolder(ViewHolder holder, int position) {
public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
holder.textView.setText(String.valueOf(position));
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package biz.laenger.android.vpbs.example.fragments;

import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
Expand All @@ -22,14 +23,14 @@ public class ViewPagerFragment extends Fragment {
@BindView(R.id.viewpager) ViewPager viewPager;

@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
final View view = inflater.inflate(R.layout.fragment_view_pager, container, false);
ButterKnife.bind(this, view);
return view;
}

@Override
public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
setupNestedViewPager();
}
Expand Down
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-2.14.1-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-4.6-all.zip
47 changes: 32 additions & 15 deletions vpbs/build.gradle
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
apply plugin: 'com.android.library'

description = 'Android BottomSheetBehavior with ViewPager support'
group = 'biz.laenger.android'
archivesBaseName = 'vpbs'
ext.title = 'ViewPagerBottomSheetBehavior'
description = 'Android BottomSheetBehavior with ViewPager support'

android {
compileSdkVersion rootProject.compileSdkVersion
Expand All @@ -10,7 +12,7 @@ android {
publishNonDefault true

defaultConfig {
minSdkVersion 9
minSdkVersion 14
targetSdkVersion rootProject.targetSdkVersion
versionName '0.0.4'
}
Expand All @@ -22,23 +24,38 @@ android {
}
}

libraryVariants.all { variant ->
variant.outputs.each { output ->
def outputFile = output.outputFile
if (outputFile != null && outputFile.name.endsWith('.aar')) {
def fileName = "${project.name}_${android.defaultConfig.versionName}_${buildVersionSuffix()}-${variant.buildType.name}.aar"
output.outputFile = new File(outputFile.parent, fileName)
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}

dependencies {
implementation "com.android.support:design:${supportVersion}"
}

android.libraryVariants.all { variant ->
renameLibraryVariantOutput(variant)

def sourcesJarTaskName = "generate${variant.name.capitalize()}SourcesJar"

task(sourcesJarTaskName, type: Jar) {
classifier = 'sources'
from variant.sourceSets*.java.srcDirs.flatten()
baseName = buildLibraryArchiveBaseName(variant)
}
}

lintOptions {
abortOnError false
def renameLibraryVariantOutput(variant) {
variant.outputs.all { output ->
if (outputFileName.endsWith('.aar')) {
outputFileName = "${buildLibraryArchiveBaseName(variant)}.aar"
}
}
}

dependencies {
compile "com.android.support:design:${supportVersion}"
def buildLibraryArchiveBaseName(variant) {
return "${project.name}_${android.defaultConfig.versionName}_${buildVersionSuffix()}-${variant.baseName}"
}

def buildVersionSuffix() {
Expand All @@ -48,4 +65,4 @@ def buildVersionSuffix() {
return 'local'
}

apply from: 'maven.gradle'
apply from: 'publish.gradle'
27 changes: 0 additions & 27 deletions vpbs/maven.gradle

This file was deleted.

73 changes: 73 additions & 0 deletions vpbs/publish.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
apply plugin: 'maven-publish'

publishing {
repositories {
maven {
name "nexus"
credentials {
username nexusUsername
password nexusPassword
}
url project.android.defaultConfig.versionName.endsWith('-SNAPSHOT') ? nexusSnapshotsRepository : nexusReleasesRepository
}
}

publications {
android.libraryVariants.each { variant ->
if (variant.buildType.name == "release") {
"${variant.name}"(MavenPublication) {
groupId project.group
artifactId project.archivesBaseName
version project.android.defaultConfig.versionName

artifact tasks["bundle${variant.name.capitalize()}"]
artifact tasks["generate${variant.name.capitalize()}SourcesJar"]

pom.withXml {
def rootNode = asNode()

rootNode.appendNode('name', project.title)
rootNode.appendNode('description', project.description)
rootNode.appendNode('url', project.scm.url)

def developersNode = rootNode.appendNode('developers')
project.developers.each {
def developerNode = developersNode.appendNode('developer')
it.each { name, value -> developerNode.appendNode(name, value) }
}

def scmNode = rootNode.appendNode('scm')
project.scm.each { name, value -> scmNode.appendNode(name, value) }

def dependenciesNode = rootNode.appendNode('dependencies')
variant.compileConfiguration.allDependencies.each {
def dependencyNode = dependenciesNode.appendNode('dependency')
dependencyNode.appendNode('groupId', it.group)
dependencyNode.appendNode('artifactId', it.name)
dependencyNode.appendNode('version', it.version)

if (!it.excludeRules.empty) {
def exclusionsNode = dependencyNode.appendNode('exclusions')
it.excludeRules.each { rule ->
def exclusionNode = exclusionsNode.appendNode('exclusion')
exclusionNode.appendNode('groupId', rule.group)
exclusionNode.appendNode('artifactId', rule.module)
}
}
}
}
}
}
}
}
}

android.libraryVariants.all { variant ->
if (variant.buildType.name == 'release') {
model {
tasks."generatePomFileFor${variant.name.capitalize()}Publication" {
destination = new File(destination.parent, "${buildLibraryArchiveBaseName(variant)}-pom.xml")
}
}
}
}
Loading

0 comments on commit 9521e09

Please sign in to comment.