插件 backend 里的 pom 文件中引入外部依赖,打包插件之后上传成功,调用插件接口报错,排查后发现是因为外部依赖没有加载。
pom.xml 文件示例
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>sls</artifactId>
<groupId>io.dataease</groupId>
<version>1.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
&lt;artifactId&gt;sls-backend&lt;/artifactId&gt;
&lt;properties&gt;
&lt;custom.lib-path&gt;${pom.basedir}/src/main/resources&lt;/custom.lib-path&gt;
&lt;/properties&gt;
&lt;dependencies&gt;
&lt;dependency&gt;
&lt;groupId&gt;io.dataease&lt;/groupId&gt;
&lt;artifactId&gt;dataease-plugin-datasource&lt;/artifactId&gt;
&lt;version&gt;1.17.0&lt;/version&gt;
&lt;scope&gt;provided&lt;/scope&gt;
&lt;/dependency&gt;
&lt;dependency&gt;
&lt;groupId&gt;com.aliyun.openservices&lt;/groupId&gt;
&lt;artifactId&gt;aliyun-log&lt;/artifactId&gt;
&lt;version&gt;0.6.75&lt;/version&gt;
&lt;exclusions&gt;
&lt;exclusion&gt;
&lt;groupId&gt;com.alibaba&lt;/groupId&gt;
&lt;artifactId&gt;fastjson&lt;/artifactId&gt;
&lt;/exclusion&gt;
&lt;/exclusions&gt;
&lt;/dependency&gt;
&lt;/dependencies&gt;
&lt;build&gt;
&lt;resources&gt;
&lt;resource&gt;
&lt;directory&gt;src/main/java&lt;/directory&gt;
&lt;includes&gt;
&lt;include&gt;**/*.properties&lt;/include&gt;
&lt;include&gt;**/*.xml&lt;/include&gt;
&lt;/includes&gt;
&lt;filtering&gt;false&lt;/filtering&gt;
&lt;/resource&gt;
&lt;resource&gt;
&lt;directory&gt;src/main/resources&lt;/directory&gt;
&lt;includes&gt;
&lt;include&gt;**/*&lt;/include&gt;
&lt;/includes&gt;
&lt;filtering&gt;false&lt;/filtering&gt;
&lt;/resource&gt;
&lt;/resources&gt;
&lt;plugins&gt;
&lt;plugin&gt;
&lt;groupId&gt;org.apache.maven.plugins&lt;/groupId&gt;
&lt;artifactId&gt;maven-compiler-plugin&lt;/artifactId&gt;
&lt;configuration&gt;
&lt;source&gt;1.8&lt;/source&gt;
&lt;target&gt;1.8&lt;/target&gt;
&lt;/configuration&gt;
&lt;/plugin&gt;
&lt;plugin&gt;
&lt;groupId&gt;org.apache.maven.plugins&lt;/groupId&gt;
&lt;artifactId&gt;maven-jar-plugin&lt;/artifactId&gt;
&lt;version&gt;2.4&lt;/version&gt;
&lt;configuration&gt;
&lt;excludes&gt;
&lt;exclude&gt;**/server/**&lt;/exclude&gt;
&lt;exclude&gt;**/*.properties&lt;/exclude&gt;
&lt;exclude&gt;**/Application*&lt;/exclude&gt;
&lt;/excludes&gt;
&lt;/configuration&gt;
&lt;/plugin&gt;
&lt;plugin&gt;
&lt;artifactId&gt;maven-clean-plugin&lt;/artifactId&gt;
&lt;configuration&gt;
&lt;filesets&gt;
&lt;fileset&gt;
&lt;directory&gt;src/main/resources/static&lt;/directory&gt;
&lt;includes&gt;
&lt;include&gt;**&lt;/include&gt;
&lt;/includes&gt;
&lt;followSymlinks&gt;false&lt;/followSymlinks&gt;
&lt;/fileset&gt;
&lt;/filesets&gt;
&lt;/configuration&gt;
&lt;/plugin&gt;
&lt;plugin&gt;
&lt;groupId&gt;org.apache.maven.plugins&lt;/groupId&gt;
&lt;artifactId&gt;maven-antrun-plugin&lt;/artifactId&gt;
&lt;executions&gt;
&lt;execution&gt;
&lt;id&gt;main-class-placement&lt;/id&gt;
&lt;phase&gt;generate-resources&lt;/phase&gt;
&lt;configuration&gt;
&lt;target&gt;
&lt;move todir="src/main/resources/static"&gt;
&lt;fileset dir="../sls-frontend/static"&gt;
&lt;include name="*.*"/&gt;
&lt;/fileset&gt;
&lt;/move&gt;
&lt;/target&gt;
&lt;/configuration&gt;
&lt;goals&gt;
&lt;goal&gt;run&lt;/goal&gt;
&lt;/goals&gt;
&lt;/execution&gt;
&lt;/executions&gt;
&lt;/plugin&gt;
&lt;plugin&gt;
&lt;artifactId&gt;maven-assembly-plugin&lt;/artifactId&gt;
&lt;configuration&gt;
&lt;archive&gt;
&lt;manifest&gt;
&lt;mainClass&gt;&lt;/mainClass&gt;
&lt;/manifest&gt;
&lt;/archive&gt;
&lt;descriptorRefs&gt;
&lt;descriptorRef&gt;jar-with-dependencies&lt;/descriptorRef&gt;
&lt;/descriptorRefs&gt;
&lt;/configuration&gt;
&lt;executions&gt;
&lt;execution&gt;
&lt;id&gt;make-assembly&lt;/id&gt;
&lt;phase&gt;package&lt;/phase&gt;
&lt;goals&gt;
&lt;goal&gt;single&lt;/goal&gt;
&lt;/goals&gt;
&lt;/execution&gt;
&lt;/executions&gt;
&lt;/plugin&gt;
&lt;/plugins&gt;
&lt;/build&gt;
</project>
build.sh 文件示例
#!/bin/sh
mvn clean package -U -Dmaven.test.skip=true
cp sls-backend/target/sls-backend-1.0-SNAPSHOT-jar-with-dependencies.jar ./sls-backend-1.0-SNAPSHOT.jar
zip -r sls.zip ./sls-backend-1.0-SNAPSHOT.jar ./slsDriver ./plugin.json