/*
 * Copyright (C) 2005-2017 Qihoo 360 Inc.
 *
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
 * use this file except in compliance with the License. You may obtain a copy of
 * the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed To in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 * License for the specific language governing permissions and limitations under
 * the License.
 *
 */

apply plugin: 'java'
apply plugin: 'groovy'
apply plugin: 'maven'
apply plugin: 'maven-publish'
//apply from: 'config.gradle'

repositories {
    jcenter()
    google()
}

buildscript {
    repositories {
        jcenter()
        google()
    }
    dependencies {
//        classpath 'com.android.tools.build:gradle:2.1.0'
        // 将项目发布到JCenter 所需要的jar   添加依赖
        classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.0'
        classpath 'com.github.dcendents:android-maven-plugin:1.2'
    }
}

group = 'com.qihoo360.replugin'  // 组名

String classPath = ".src.main.groovy.com.qihoo360.replugin.gradle.plugin.AppConstant".replace(".", java.io.File.separator)
String verPath = "${project.projectDir}" + classPath + ".groovy"
String verLine = new File(verPath).filterLine { it =~ /def static final VER =/ }
version = "${verLine.split("\"")[1]}" // 版本
//红色醒目打印显示版本号
java.lang.System.err.println "version=${version}"

sourceSets {
    main {
        groovy {
            srcDirs '../replugin-host-gradle-androidx/src/main/groovy/com/qihoo360/replugin/gradle/compat'
        }
    }
}

dependencies {
    compile 'com.android.tools.build:gradle:3.5.3'
    compile 'org.json:json:20160212'
    compile 'org.codehaus.groovy:groovy:2.4.7'
    compile 'com.squareup:javapoet:1.5.1'
    compile 'com.android.tools.build:transform-api:1.5.0'
    compile 'javassist:javassist:3.12.1.GA'
    compile 'commons-io:commons-io:2.5'

    compile gradleApi()
    compile localGroovy()

    compile 'com.google.gradle:osdetector-gradle-plugin:1.2.1'
}

//if (project.hasProperty("android")) { // Android libraries
//    task sourcesJar(type: Jar) {
//        classifier = 'sources'
//        from android.sourceSets.main.java.srcDirs
//    }
//
//    task javadoc(type: Javadoc) {
//        source = android.sourceSets.main.java.srcDirs
//        classpath += project.files(android.getBootClasspath().join(File.pathSeparator))
//    }
//} else { // Java libraries
//    task sourcesJar(type: Jar, dependsOn: classes) {
//        classifier = 'sources'
//        from sourceSets.main.allSource
//    }
//}

// 强制 Java/JavaDoc 等的编码为 UTF-8
tasks.withType(JavaCompile) {
    options.encoding = "UTF-8"
}

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



// add javadoc/source jar tasks as artifacts
//artifacts {
//    archives sourcesJar, javadocJar
//}

publishing {
    publications {
        mavenJava(MavenPublication) {
            if (plugins.hasPlugin('war')) {
                from components.web
            } else {
                from components.java
            }

//            artifact sourcesJar
//            artifact javadocJar
        }
    }
}

project.ext.RP_ARTIFACT_ID = 'replugin-plugin-gradle-androidx'
apply from: '../rp-publish.gradle'