Skip to content

Commit

Permalink
拆模块
Browse files Browse the repository at this point in the history
  • Loading branch information
yhyzgn committed Nov 3, 2021
1 parent c8c4535 commit fadd124
Show file tree
Hide file tree
Showing 90 changed files with 1,896 additions and 240 deletions.
189 changes: 14 additions & 175 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,185 +1,24 @@
import java.text.SimpleDateFormat

plugins {
id "java-library"
id "maven-publish"
id "signing"
}

repositories {
mavenCentral()
gradlePluginPortal()
google()
}

apply from: "ext.gradle"

group rootProject.ext.groupId
version rootProject.ext.version

sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8

dependencies {
testImplementation group: 'junit', name: 'junit', version: '4.12'

api 'com.squareup.okhttp3:okhttp:5.0.0-alpha.2' // 新版本(kotlin 版本)
// api 'com.squareup.okhttp3:okhttp:3.14.9' // 已兼容旧版本(java 版本)
api 'com.fasterxml.jackson.core:jackson-core:2.12.3'
api 'com.fasterxml.jackson.core:jackson-databind:2.12.3'
api 'com.google.code.gson:gson:2.8.6'
api 'com.google.guava:guava:29.0-jre'
api 'org.jetbrains:annotations:13.0'
compileOnly 'org.slf4j:slf4j-api:2.0.0-alpha1'
compileOnly 'org.jetbrains:annotations:19.0.0'
testImplementation 'org.slf4j:slf4j-simple:2.0.0-alpha1'
}

tasks.withType(JavaCompile) {
options.encoding = 'UTF-8'
options.warnings = false
options.deprecation = true
options.compilerArgs += ["-parameters"]
}

tasks.withType(GenerateModuleMetadata) {
enabled = false
}

compileJava.dependsOn(clean)

// https://docs.spring.io/spring-boot/docs/current/gradle-plugin/reference/htmlsingle/#packaging-executable.and-plain-archives
jar {
enabled true
classifier ''
afterEvaluate {
manifest {
attributes 'Implementation-Version': archiveVersion
attributes 'Built-Gradle': gradle.gradleVersion
attributes 'Bundle-DocURL': '/~https://github.com/yhyzgn/'
attributes 'Build-OS': System.getProperty("os.name")
attributes 'Built-By': System.getProperty("user.name")
attributes 'Build-Jdk': System.getProperty("java.version")
attributes 'Build-Timestamp': new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date())
}
}
id 'java'
}

javadoc {
description = "生成jar格式的javadoc。"
// 只显示 protected 和 public 的类和成员
options.memberLevel = JavadocMemberLevel.PROTECTED
options.author = true
options.version = true
options.header = project.name
// 静默javadoc检查(比如不支持@date会报错等),jdk 8+
options.addStringOption('Xdoclint:none', '-quiet')
// 防止本地打开中文乱码
options.addStringOption("charset", "UTF-8")
// suppress warnings due to cross-module @see and @link references;
// note that global 'api' task does display all warnings.
logging.captureStandardError LogLevel.INFO
// suppress "## warnings" message
logging.captureStandardOutput LogLevel.INFO
// 编码一定要配置否则直接出错
options.encoding = "UTF-8"
options.charSet = "UTF-8"
// java9
if (JavaVersion.current().isJava9Compatible()) {
options.addBooleanOption('html5', true)
}
}
apply from: 'ext.gradle'

task replaceVersion() {
ant.replaceregexp(
file: "./src/main/java/com/yhy/http/pigeon/utils/Utils.java",
match: "public final static String VERSION = \"(.+)\"",
replace: "public final static String VERSION = \"${rootProject.ext.version}\"",
flags: 'g',
byline: "true"
)
}

task sourceJar(type: Jar) {
classifier "sources"
from sourceSets.main.allJava
}
def rootConfig = rootProject.ext

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

javadoc {
afterEvaluate {
configure(options) {
encoding "UTF-8"
charSet 'UTF-8'
author true
version true
failOnError false
links "http://docs.oracle.com/javase/8/docs/api"
}
}
}

compileJava.dependsOn replaceVersion

java {
withJavadocJar()
withSourcesJar()
}

publishing {
publications {
mavenJava(MavenPublication) {
groupId = rootProject.ext.groupId
artifactId = rootProject.ext.artifactId
version = rootProject.ext.version
from components.java

pom {
name = rootProject.ext.artifactId
description = rootProject.ext.description
url = "https://${rootProject.ext.url}"
licenses {
license {
name = 'Apache License, Version 2.0'
url = 'http://www.apache.org/licenses/LICENSE-2.0.txt'
distribution = 'repo'
comments = 'A business-friendly OSS license'
}
}
developers {
developer {
name = 'yhyzgn'
email = 'yhyzgn@gmail.com'
url = "/~https://github.com/yhyzgn/"
}
}
scm {
url = "https://${rootProject.ext.url}.git"
connection = "scm:git:https://${rootProject.ext.url}.git"
developerConnection = "scm:git:https://${rootProject.ext.url}.git"
}
}
}
}
group rootConfig.group
version rootConfig.version

allprojects {
repositories {
maven {
name "oss"
def releasesRepoUrl = "https://oss.sonatype.org/service/local/staging/deploy/maven2/"
def snapshotsRepoUrl = "https://oss.sonatype.org/content/repositories/snapshots/"
url = version.endsWith('SNAPSHOT') ? snapshotsRepoUrl : releasesRepoUrl
credentials {
username = ossrhUsername
password = ossrhPassword
}
}
mavenLocal()
mavenCentral()
gradlePluginPortal()
google()
}
}

signing {
sign publishing.publications.mavenJava
//编译JAVA文件时采用UTF-8
tasks.withType(JavaCompile) {
options.encoding = "UTF-8"
}
}
42 changes: 37 additions & 5 deletions ext.gradle
Original file line number Diff line number Diff line change
@@ -1,7 +1,39 @@
ext {
groupId = 'com.yhyzgn.http'
artifactId = 'pigeon'
version = '1.5.3'
description = 'Java http client with OkHttp3.'
url = 'github.com/yhyzgn/pigeon'
group = 'com.yhyzgn.http'
version = '0.0.1-SNAPSHOT'
url = 'github.com/yhyzgn/pigeon' as Object
repository = [
release : 'https://oss.sonatype.org/service/local/staging/deploy/maven2/',
snapshot: 'https://oss.sonatype.org/content/repositories/snapshots/'
] as LinkedHashMap
pigeon = [
artifact : 'pigeon',
version : '1.5.4',
description: 'Java http client with OkHttp3.'
] as LinkedHashMap
spring = [
artifact : 'pigeon-spring',
version : '1.0.0',
description: 'Spring supported.'
]
starterAbstract = [
artifact : 'pigeon-spring-starter-abstract',
version : '1.0.0',
description: 'Spring boot supported abstractly.'
]
starter = [
artifact : 'pigeon-spring-boot-starter',
version : '1.0.0',
description: 'Spring boot starter.'
]
starterSimple = [
artifact : 'pigeon-spring-boot-starter-simple',
version : '1.0.0',
description: 'Spring boot starter simple.'
]
starterSimpleApi = [
artifact : 'pigeon-spring-boot-starter-simple-api',
version : '1.0.0',
description: 'Spring boot starter simple api.'
]
}
34 changes: 34 additions & 0 deletions pigeon-spring-boot-starter-simple-api/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
plugins {
id 'org.springframework.boot' version '2.5.0'
id 'io.spring.dependency-management' version '1.0.11.RELEASE'
id "java"
}

apply from: "../ext.gradle"

def rootConfig = rootProject.ext

group rootConfig.group
version rootConfig.starterSimpleApi.version

configurations {
compileOnly {
extendsFrom annotationProcessor
}
}

dependencies {
implementation 'org.springframework.boot:spring-boot-starter-web'
implementation 'org.springframework.boot:spring-boot-autoconfigure'
implementation 'com.tengyun.saas:lib-util:1.0.0-SNAPSHOT'

compileOnly 'org.projectlombok:lombok'
annotationProcessor 'org.projectlombok:lombok'

testImplementation 'org.junit.jupiter:junit-jupiter-api:5.7.0'
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.7.0'
}

test {
useJUnitPlatform()
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package com.yhy.http.pigeon.spring.starter.simple.api;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

/**
* Created on 2021-05-22 17:13
*
* @author 颜洪毅
* @version 1.0.0
* @since 1.0.0
*/
@SpringBootApplication
public class Application {

public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package com.yhy.http.pigeon.spring.starter.simple.api.controller;

import com.tengyun.saas.lib.util.response.Res;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
* Created on 2021-05-22 18:03
*
* @author 颜洪毅
* @version 1.0.0
* @since 1.0.0
*/
@Slf4j
@RestController
@RequestMapping("/api/normal")
public class NormalController {

@GetMapping("/get")
public Res get(@RequestHeader(value = "Token", required = false) String token) {
log.info("token = {}", token);
return Res.success(token, "成功");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
server:
port: 8888

spring:
application:
name: pigeon-simple-api
36 changes: 36 additions & 0 deletions pigeon-spring-boot-starter-simple/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
plugins {
id 'org.springframework.boot' version '2.5.0'
id 'io.spring.dependency-management' version '1.0.11.RELEASE'
id "java"
}

apply from: "../ext.gradle"

def rootConfig = rootProject.ext

group rootConfig.group
version rootConfig.starterSimple.version

configurations {
compileOnly {
extendsFrom annotationProcessor
}
}

dependencies {
implementation 'org.springframework.boot:spring-boot-starter-web'
implementation 'org.springframework.boot:spring-boot-autoconfigure'
implementation 'com.tengyun.saas:lib-util:1.0.0-SNAPSHOT'

implementation project(':pigeon-spring-boot-starter')

compileOnly 'org.projectlombok:lombok'
annotationProcessor 'org.projectlombok:lombok'

testImplementation 'org.junit.jupiter:junit-jupiter-api:5.7.0'
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.7.0'
}

test {
useJUnitPlatform()
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package com.yhy.http.pigeon.spring.starter.simple;

import com.yhy.http.pigeon.spring.starter.annotation.EnablePigeon;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

/**
* Created on 2021-11-03 12:58
*
* @author 颜洪毅
* @version 1.0.0
* @since 1.0.0
*/
@EnablePigeon
@SpringBootApplication
public class Application {

public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
}
Loading

0 comments on commit fadd124

Please sign in to comment.