-
Notifications
You must be signed in to change notification settings - Fork 503
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
gradle implementation for the Ark plugin #1012
Changes from 6 commits
ba8cbc5
538c17a
ecf4a38
5c215d9
d44e293
0bcf652
33850a6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,151 @@ | ||
# Ark Plugin Gradle打包插件使用 | ||
`sofa-ark-plugin-gradle-plugin`模块是Ark Plugin打包工具的Gradle版本实现,和Maven打包工具`sofa-ark-plugin-maven-plugin`有同样的功能。在后文,使用**Gradle插件**来指代`sofa-ark-plugin-gradle-plugin`。 | ||
|
||
本小节会对**Gradle插件**进行介绍,随后会展示如何使用**Gradle插件**打包Ark Plugin。 | ||
|
||
### 配置项 | ||
**Gradle插件**提供了和Maven基本相同的配置项,在使用上略有不同,想要使用配置项,需要在打包的项目build.gradle使用arkPlugin: | ||
|
||
``` | ||
arkPlugin{ | ||
//具体配置项 | ||
} | ||
``` | ||
|
||
- activator使用 | ||
``` | ||
activator = 'sample.activator.SamplePluginActivator' | ||
``` | ||
|
||
- excludes使用 | ||
``` | ||
excludes = ['com.fasterxml.jackson.module:jackson-module-parameter-names', 'org.example:common'] | ||
``` | ||
|
||
- exported使用 | ||
``` | ||
exported { | ||
packages = [ | ||
'com.alipay.sofa.ark.sample.common' | ||
|
||
] | ||
classes = [ | ||
'sample.facade.SamplePluginService' | ||
] | ||
|
||
resource = [ | ||
'META-INF/spring/bean.xml' | ||
] | ||
|
||
} | ||
``` | ||
|
||
|
||
### 引入 | ||
引入方式可以分为两种: | ||
1. 本地引入 | ||
2. 远程引入(正在申请) | ||
|
||
本地引入的方式是将Gradle插件发布到本地的Maven仓库中,之后使用Gradle进行加载。 | ||
|
||
#### 将Gradle插件发布到本地仓库 | ||
1. 在**Gradle插件**的build.gradle的plugin解开注释,如下所示: | ||
``` | ||
plugins { | ||
id 'java' | ||
id 'java-gradle-plugin' | ||
|
||
// 本地调试用,发布到maven | ||
id 'maven-publish' | ||
} | ||
``` | ||
|
||
2. 配置publish | ||
在build.gradle中增加如下内容: | ||
``` | ||
publishing { | ||
// 配置Plugin GAV | ||
publications { | ||
maven(MavenPublication) { | ||
groupId = group | ||
artifactId = 'plugin' | ||
version = version | ||
from components.java | ||
} | ||
} | ||
// 配置仓库地址 | ||
repositories { | ||
maven { | ||
url file('E:/repo') | ||
} | ||
|
||
} | ||
} | ||
``` | ||
点击在IDEA的右侧Gradle中的 Tasks > publishing > publish 将插件发布到本地仓库。 | ||
|
||
#### 在本地项目中引入 | ||
|
||
1. 在Gradle项目根目录的setting.gradle中设置pluginManagement | ||
|
||
``` | ||
pluginManagement { | ||
repositories { | ||
// 指定maven仓库 | ||
maven { | ||
url "file:///E:/repo" | ||
} | ||
} | ||
} | ||
``` | ||
|
||
2. 在需要打包的项目中的build.gradle进行如下的配置 | ||
|
||
``` | ||
buildscript { | ||
repositories { | ||
// ... | ||
maven { | ||
url "file:///E:/repo" | ||
} | ||
|
||
} | ||
dependencies { | ||
classpath("sofa.ark.gradle:sofa-ark-gradle-plugin:1.1") | ||
} | ||
} | ||
|
||
plugins { | ||
id 'sofa.ark.gradle.plugin' version "1.1" | ||
} | ||
``` | ||
|
||
3. 增加配置 | ||
|
||
在需要打包的项目中的build.gradle创建配置项: | ||
|
||
``` | ||
arkPlugin{ | ||
outputDirectory = layout.buildDirectory.dir("custom-output") | ||
|
||
activator = 'sample.activator.SamplePluginActivator' | ||
excludes = ['com.fasterxml.jackson.module:jackson-module-parameter-names'] | ||
|
||
shades = [ | ||
'org.example:common:1.0' | ||
] | ||
exported { | ||
packages = [ | ||
'com.alipay.sofa.ark.sample.common' | ||
|
||
] | ||
classes = [ | ||
'sample.facade.SamplePluginService' | ||
] | ||
|
||
} | ||
} | ||
|
||
``` | ||
|
||
使用Gradle刷新后,如果一切正常,会在IDEA右侧Gradle任务列表中出现arkPluginJar,具体如下: Tasks > build > arkPluginJar,点击arkPluginJa执行,会在指定的outputDirectory中输出Ark Plugin包。 |
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,54 @@ | ||||||||||||||||||||||||
plugins { | ||||||||||||||||||||||||
id 'java' | ||||||||||||||||||||||||
id 'java-gradle-plugin' | ||||||||||||||||||||||||
id 'maven-publish' | ||||||||||||||||||||||||
} | ||||||||||||||||||||||||
|
||||||||||||||||||||||||
ext { | ||||||||||||||||||||||||
arkPluginGradlePluginId = 'sofa-ark-plugin-gradle-plugin' | ||||||||||||||||||||||||
} | ||||||||||||||||||||||||
|
||||||||||||||||||||||||
group = 'com.alipay.sofa' | ||||||||||||||||||||||||
version = '1.0.0' | ||||||||||||||||||||||||
sourceCompatibility = '1.8' | ||||||||||||||||||||||||
|
||||||||||||||||||||||||
gradlePlugin { | ||||||||||||||||||||||||
plugins { | ||||||||||||||||||||||||
DependenciesPlugin{ | ||||||||||||||||||||||||
id = arkPluginGradlePluginId | ||||||||||||||||||||||||
implementationClass = 'com.alipay.sofa.ark.boot.mojo.ArkPlugin' | ||||||||||||||||||||||||
} | ||||||||||||||||||||||||
} | ||||||||||||||||||||||||
} | ||||||||||||||||||||||||
|
||||||||||||||||||||||||
repositories { | ||||||||||||||||||||||||
mavenLocal() | ||||||||||||||||||||||||
mavenCentral() | ||||||||||||||||||||||||
} | ||||||||||||||||||||||||
|
||||||||||||||||||||||||
dependencies { | ||||||||||||||||||||||||
implementation 'org.apache.commons:commons-compress:1.26.0' | ||||||||||||||||||||||||
testImplementation 'junit:junit:4.13.1' | ||||||||||||||||||||||||
testRuntimeOnly("org.junit.vintage:junit-vintage-engine:5.8.2") | ||||||||||||||||||||||||
} | ||||||||||||||||||||||||
Comment on lines
+29
to
+33
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Consider migrating to JUnit 5 for testing. Since this is a new project, consider using JUnit 5 directly instead of JUnit 4 with the vintage engine. - testImplementation 'junit:junit:4.13.1'
- testRuntimeOnly("org.junit.vintage:junit-vintage-engine:5.8.2")
+ testImplementation 'org.junit.jupiter:junit-jupiter-api:5.8.2'
+ testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.8.2' 📝 Committable suggestion
Suggested change
|
||||||||||||||||||||||||
|
||||||||||||||||||||||||
publishing { | ||||||||||||||||||||||||
publications { | ||||||||||||||||||||||||
maven(MavenPublication) { | ||||||||||||||||||||||||
from components.java | ||||||||||||||||||||||||
groupId = project.group | ||||||||||||||||||||||||
artifactId = arkPluginGradlePluginId | ||||||||||||||||||||||||
version = project.version | ||||||||||||||||||||||||
} | ||||||||||||||||||||||||
} | ||||||||||||||||||||||||
// publish to local maven repository | ||||||||||||||||||||||||
repositories { | ||||||||||||||||||||||||
maven { | ||||||||||||||||||||||||
mavenLocal() | ||||||||||||||||||||||||
} | ||||||||||||||||||||||||
} | ||||||||||||||||||||||||
} | ||||||||||||||||||||||||
|
||||||||||||||||||||||||
tasks.named('test') { | ||||||||||||||||||||||||
useJUnitPlatform() | ||||||||||||||||||||||||
} | ||||||||||||||||||||||||
Comment on lines
+52
to
+54
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Consider enhancing test configuration. While the basic JUnit Platform configuration is correct, consider adding:
tasks.named('test') {
useJUnitPlatform()
+ testLogging {
+ events "passed", "skipped", "failed"
+ exceptionFormat "full"
+ }
+ maxParallelForks = Runtime.runtime.availableProcessors().intdiv(2) ?: 1
} 📝 Committable suggestion
Suggested change
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You 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. | ||
*/ | ||
package com.alipay.sofa.ark.boot.mojo; | ||
|
||
import org.gradle.api.Plugin; | ||
import org.gradle.api.Project; | ||
|
||
public class ArkPlugin implements Plugin<Project> { | ||
|
||
@Override | ||
public void apply(Project project) { | ||
project.getExtensions().create("arkPlugin", ArkPluginExtension.class, project); | ||
project.getTasks().register("arkPluginJar", ArkPluginJarTask.class, | ||
task -> { | ||
task.setGroup("build"); | ||
task.setDescription("Generates an Ark plugin JAR file"); | ||
} | ||
); | ||
} | ||
|
||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion
Consider upgrading Java compatibility version.
While Java 1.8 is still widely used, consider upgrading to a more recent LTS version (e.g., 11 or 17) for better features and security, if your ecosystem supports it.
📝 Committable suggestion