Skip to content

Commit

Permalink
[ISSUE #550] Deduplicate plugin jar (#558)
Browse files Browse the repository at this point in the history
* Deduplicate plugin jar

* Remove example in dist

* Add DuplicatesStrategy.EXCLUDE when copy dist/conf

* Remove eventmesh lib from lib
  • Loading branch information
ruanwenjun committed Oct 17, 2021
1 parent 9b2b1c7 commit dfbe08c
Show file tree
Hide file tree
Showing 10 changed files with 127 additions and 94 deletions.
153 changes: 82 additions & 71 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,45 @@ task zip(type: Zip) {
}
}

task installPlugin() {
if (!new File("${rootDir}/dist").exists()) {
return
}
// pluginType -> [pluginInstanceName -> moduleName]
Map<String, Map<String, String>> pluginTypeMap = [
"connector": ["rocketmq": "eventmesh-connector-rocketmq", "standalone": "eventmesh-connector-standalone",],
"security" : ["acl": "eventmesh-security-acl",],
"registry" : ["namesrv": "eventmesh-registry-namesrv",]
]
String[] libJars = java.util.Optional.ofNullable(new File("${rootDir}/dist/lib").list()).orElseGet(() -> new String[0])
getAllprojects().forEach(subProject -> {
pluginTypeMap.forEach((pluginType, pluginInstanceMap) -> {
pluginInstanceMap.forEach((pluginInstanceName, moduleName) -> {
if (moduleName == subProject.name) {
println String.format("install plugin, pluginType: %s, pluginInstanceName: %s, module: %s",
pluginType, pluginInstanceName, moduleName)

new File("${rootDir}/dist/plugin/${pluginType}/${pluginInstanceName}").mkdirs()
copy {
into "${rootDir}/dist/plugin/${pluginType}/${pluginInstanceName}"
from "${subProject.getProjectDir()}/dist/apps"
}
copy {
into "${rootDir}/dist/plugin/${pluginType}/${pluginInstanceName}"
from "${subProject.getProjectDir()}/dist/lib/"
exclude(libJars)
}
copy {
into "${rootDir}/dist/conf"
from "${subProject.getProjectDir()}/dist/conf"
exclude 'META-INF'
}
}
})
})
})
}

subprojects {

apply plugin: "io.spring.dependency-management"
Expand Down Expand Up @@ -187,90 +226,62 @@ subprojects {
}
}

// pluginType:
// pluginInstanceName:
// moduleName
Map<String, Map<String, String>> pluginTypeMap = [
"connector": [
"rocketmq" : "eventmesh-connector-rocketmq",
"standalone": "eventmesh-connector-standalone",
],
"security" : [
"acl": "eventmesh-security-acl",
],
"registry" : [
"namesrv": "eventmesh-registry-namesrv",
]
]

task dist(dependsOn: ['jar']) {
doFirst {
new File(projectDir, '../dist/bin').mkdirs()
new File(projectDir, '../dist/apps').mkdirs()
new File(projectDir, '../dist/conf').mkdirs()
new File(projectDir, '../dist/lib').mkdirs()
new File("${projectDir}/dist/bin").mkdirs()
new File("${projectDir}/dist/apps").mkdirs()
new File("${projectDir}/dist/conf").mkdirs()
new File("${projectDir}/dist/lib").mkdirs()
}

Set<String> rootProject = ["eventmesh-admin",
"eventmesh-common",
"eventmesh-connector-api",
"eventmesh-registry-api",
"eventmesh-runtime",
"eventmesh-security-api",
"eventmesh-starter",
"eventmesh-spi"]
doLast {
pluginTypeMap.forEach((pluginType, pluginInstanceMap) -> {
pluginInstanceMap.forEach((pluginInstanceName, moduleName) -> {
if (moduleName == project.name) {
println String.format("install plugin, pluginType: %s, pluginInstanceName: %s, module: %s",
pluginType, pluginInstanceName, moduleName)
new File("${rootDir}/dist/plugin/${pluginType}/${pluginInstanceName}").mkdirs()
copy {
into "${rootDir}/dist/plugin/${pluginType}/${pluginInstanceName}"
from project.jar.getArchivePath()
}
copy {
into "${rootDir}/dist/plugin/${pluginType}/${pluginInstanceName}"
from project.configurations.runtimeClasspath
}
copy {
into "${rootDir}/dist/conf"
from sourceSets.main.resources.srcDirs
exclude 'META-INF'
}
}
})
})

copy {
into('../dist/apps/')
into("${projectDir}/dist/apps")
from project.jar.getArchivePath()
// exclude 'eventmesh-common*.jar'
// exclude 'eventmesh-connector-api*.jar'
// exclude 'eventmesh-connector-plugin*.jar'
// exclude 'eventmesh-admin*.jar'
// exclude 'eventmesh-starter*.jar'
// exclude 'eventmesh-test*.jar'
// exclude 'eventmesh-sdk*.jar'
}
copy {
into '../dist/lib'
into("${projectDir}/dist/lib")
from project.configurations.runtimeClasspath
exclude '**/*.properties*'
exclude '**/*testng*.jar'
exclude '**/*powermock*.jar'
exclude '**/*mockito*.jar'
exclude '**/*junit*.jar'
exclude '**/*jacoco*.jar'
exclude '**/*log4j2.xml*'
exclude '**/spring-boot-devtools*.jar'
exclude '**/mumble-sdk-test*.jar'
exclude 'eventmesh*.jar'
// exclude 'eventmesh-runtime*.jar'
exclude 'commons-collections-3.2.2.jar'
}

copy {
into '../dist/bin'
from '../eventmesh-runtime/bin'
into("${projectDir}/dist/bin")
from 'bin'
}

copy {
into '../dist/conf'
from '../eventmesh-runtime/conf'
into("${projectDir}/dist/conf")
from 'conf', sourceSets.main.resources.srcDirs
setDuplicatesStrategy(DuplicatesStrategy.EXCLUDE)
exclude 'META-INF'
}
if (rootProject.contains(project.name)) {
new File("${rootDir}/dist/apps").mkdirs()
new File("${rootDir}/dist/lib").mkdirs()
new File("${rootDir}/dist/bin").mkdirs()
new File("${rootDir}/dist/conf").mkdirs()
copy {
into("${rootDir}/dist/apps")
from "${projectDir}/dist/apps"
}
copy {
into "${rootDir}/dist/lib"
from "${projectDir}/dist/lib"
exclude "eventmesh-*"
}
copy {
into "${rootDir}/dist/bin"
from "${projectDir}/dist/bin"
}
copy {
into "${rootDir}/dist/conf"
from "${projectDir}/dist/conf"
}
}
}
}
Expand Down
28 changes: 16 additions & 12 deletions docs/cn/instructions/eventmesh-runtime-quickstart.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,22 +68,26 @@ sh start.sh
> 插件实例需要在对应模块中的/main/resources/META-INF/eventmesh 下配置相关接口与实现类的映射文件,文件名为SPI接口全类名.
> 文件内容为插件实例名到插件实例的映射, 具体可以参考eventmesh-connector-rocketmq插件模块
插件可以从classpath和插件目录下面加载. 在本地开发阶段可以将使用的插件在eventmesh-starter模块build.gradle中进行声明,或者执行gradle的dist任务
将插件拷贝至dist/plugin目录下, eventmesh默认会加载项目下dist/plugin目录下的插件, 加载目录可以通过-DeventMeshPluginDir=your_plugin_directory来改变插件目录.
运行时需要使用的插件实例可以在eventmesh.properties中进行配置.如果需要使用rocketmq插件实行快速启动,需要在eventmesh-starter模块build.gradle中进行如下声明
```
implementation project(":eventmesh-connector-plugin:eventmesh-connector-rocketmq")
```
**2.3.2 插件说明**

**2.3.2 配置插件**
***2.3.2.1 安装插件***

`eventMesh.properties`配置文件通过声明式的方式来指定项目启动后需要加载的插件

修改`confPath`目录下面的`eventMesh.properties`文件
有两种方式安装插件
- classpath加载:本地开发可以通过在eventmesh-starter模块build.gradle中进行声明,例如声明使用rocketmq插件
```java
implementation project(":eventmesh-connector-plugin:eventmesh-connector-rocketmq")
```
- 文件加载:通过将插件安装到插件目录,EventMesh在运行时会根据条件自动加载插件目录下的插件,可以通过执行以下命令安装插件
```shell
./gradlew clean jar dist
./gradlew installPlugin
```

加载**RocketMQ Connector**插件配置:
***2.3.2.2 使用插件***

```java
EventMesh会默认加载dist/plugin目录下的插件,可以通过`-DeventMeshPluginDir=your_plugin_directory`来改变插件目录。运行时需要使用的插件实例可以在
`confPath`目录下面的`eventmesh.properties`中进行配置。例如通过以下设置声明在运行时使用rocketmq插件。
```properties
#connector plugin
eventMesh.connector.plugin.type=rocketmq
```
Expand Down
24 changes: 21 additions & 3 deletions docs/en/instructions/eventmesh-runtime-quickstart.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,31 @@ Same with 1.2

**2.3.1 Configure plugin**

Specify the connector plugin that will be loaded after the project start by declaring in `eventMesh.properties`
***2.3.1.1 Install Plugin***

Modify the `eventMesh.properties` file in the `confPath` directory
There are two ways to install the plugin:
- Install from classpath: Local development can be done by declaring in the eventmesh-starter module build.gradle, for example
by declaring the use of rocketmq plugin
```java
implementation project(":eventmesh-connector-plugin:eventmesh-connector-rocketmq")
```

- Install from files: By installing the plugin into the plugin directory, EventMesh will automatically load the plugins in the plugin directory
according to the conditions when EventMesh running, you can install the plugins by executing the following command.
```shell
./gradlew clean jar dist
./gradlew installPlugin
```

***2.3.1.2 Use Plugin***

EventMesh will default load plugins installed in `dist/plugin`, you can change the plugin directory by `-DeventMeshPluginDir=your_plugin_directory`.
The plugin instance to be used at runtime can be configured in the `eventmesh.properties` at the `confPath` directory.
Example you can declare use rocketmq by following config.

```java
#connector plugin, default standalone, can be rocketmq
eventMesh.connector.plugin.type=standalone
eventMesh.connector.plugin.type=rocketmq
```

**2.3.2 Configure VM Options**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
*/

dependencies {
compileOnly project(":eventmesh-spi")
compileOnly project(":eventmesh-common")
implementation project(":eventmesh-spi")
implementation project(":eventmesh-common")
api 'io.openmessaging:openmessaging-api'
api 'io.dropwizard.metrics:metrics-core'
api "io.dropwizard.metrics:metrics-healthchecks"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ List rocketmq = [

dependencies {
compileOnly project(":eventmesh-common")
implementation project(":eventmesh-connector-plugin:eventmesh-connector-api")
compileOnly project(":eventmesh-connector-plugin:eventmesh-connector-api")
implementation rocketmq

testImplementation project(":eventmesh-connector-plugin:eventmesh-connector-api")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

dependencies {
compileOnly project(":eventmesh-common")
implementation project(":eventmesh-connector-plugin:eventmesh-connector-api")
compileOnly project(":eventmesh-connector-plugin:eventmesh-connector-api")

testImplementation project(":eventmesh-connector-plugin:eventmesh-connector-api")
testImplementation project(":eventmesh-common")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
*/

dependencies {
compileOnly project(":eventmesh-spi")
implementation project(":eventmesh-spi")

testImplementation project(":eventmesh-spi")
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* limitations under the License.
*/
dependencies {
implementation project(":eventmesh-registry-plugin:eventmesh-registry-api")
compileOnly project(":eventmesh-registry-plugin:eventmesh-registry-api")

testImplementation project(":eventmesh-registry-plugin:eventmesh-registry-api")
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
*/

dependencies {
implementation project(":eventmesh-security-plugin:eventmesh-security-api")
compileOnly project(":eventmesh-security-plugin:eventmesh-security-api")

testImplementation project(":eventmesh-security-plugin:eventmesh-security-api")
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
*/

dependencies {
compileOnly project(":eventmesh-spi")
implementation project(":eventmesh-spi")

testImplementation project(":eventmesh-spi")
}

0 comments on commit dfbe08c

Please sign in to comment.