风格检查
跳出风格检查
mvn clean -Dcheckstyle.skip=true test
Download Sources
mvn dependency:resolve -Dclassifier=sources
maven-checkstyle-plugin
maven中一个名为maven-checkstyle-plugin的插件,用于执行CheckStyle。
[ERROR] src/main/java/org/apache/orc/impl/RecordReaderBinaryUtils.java:[45] (imports) ImportOrder: Wrong order for 'org.slf4j.Logger' import.
此时要挪一下 org.slf4j.Logger 的位置
从
import org.apache.spark.sql.types.StructType;
import org.apache.spark.unsafe.Platform;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
挪到
import org.apache.orc.storage.common.io.DiskRange;
import org.apache.orc.storage.common.io.DiskRangeList;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
‘static’ modifier out of order with the JLS suggestions,
public final static boolean[] READ_ALL_RGS = null;
需要调整为
public static final boolean[] READ_ALL_RGS = null;
(whitespace) MethodParamPad: ‘(’ should be on the previous line.
static DiskRangeList planReadPartialDataStreams
(List<OrcProto.Stream> streamList,
修改为
static DiskRangeList planReadPartialDataStreams(
List<OrcProto.Stream> streamList,
(indentation) CommentsIndentation: Comment has incorrect indentation level 0, expected is 4, indentation should be the same level as line 1,226.
修改注释缩进
style check
专门检查 style 的mvn command
mvn scalastyle:check -Pspark-ut
cases
2023-01-04T12:17:49.5713870Z error file=/opt/gluten/gluten-ut/src/test/scala/org/apache/spark/sql/GlutenJoinSuite.scala message=illegal start of simple expression: Token(RPAREN,),2114,))
这个一般是 集合最后一个元素,多了 逗号
error file=/mnt/DP_disk2/zhixingheyi-tian/gluten_JS/gluten-ut/src/test/scala/org/apache/spark/sql/GlutenJoinSuite.scala message=Expected token RBRACE but got Token(EOF,,2115,)
这个问题一般是缺少最后一个 “}”
assembly
assembly.xml
https://maven.apache.org/plugins/maven-assembly-plugin/assembly.html
下面是一个 spark 打包实例
https://spark.apache.org/developer-tools.html
<assembly>
<id>dist</id>
<formats>
<format>tar.gz</format>
<format>dir</format>
</formats>
<includeBaseDirectory>false</includeBaseDirectory>
<fileSets>
<fileSet>
<includes>
<include>README</include>
</includes>
</fileSet>
<fileSet>
<directory>
${project.parent.basedir}/core/src/main/resources/org/apache/spark/ui/static/
</directory>
<outputDirectory>ui-resources/org/apache/spark/ui/static</outputDirectory>
<includes>
<include>**/*</include>
</includes>
</fileSet>
<fileSet>
<directory>
${project.parent.basedir}/sbin/
</directory>
<outputDirectory>sbin</outputDirectory>
<includes>
<include>**/*</include>
</includes>
</fileSet>
<fileSet>
<directory>
${project.parent.basedir}/bin/
</directory>
<outputDirectory>bin</outputDirectory>
<includes>
<include>**/*</include>
</includes>
</fileSet>
<fileSet>
<directory>
${project.parent.basedir}/assembly/target/${spark.jar.dir}
</directory>
<outputDirectory></outputDirectory>
<includes>
<include>${spark.jar.basename}</include>
</includes>
</fileSet>
</fileSets>
<dependencySets>
<dependencySet>
<includes>
<include>org.apache.spark:*:jar</include>
</includes>
<excludes>
<exclude>org.apache.spark:spark-assembly:jar</exclude>
</excludes>
</dependencySet>
<dependencySet>
<outputDirectory>lib</outputDirectory>
<useTransitiveDependencies>true</useTransitiveDependencies>
<unpack>false</unpack>
<scope>runtime</scope>
<useProjectArtifact>false</useProjectArtifact>
<excludes>
<exclude>org.apache.hadoop:*:jar</exclude>
<exclude>org.apache.spark:*:jar</exclude>
<exclude>org.apache.zookeeper:*:jar</exclude>
<exclude>org.apache.avro:*:jar</exclude>
</excludes>
</dependencySet>
</dependencySets>
</assembly>
- id: 则是添加到打包文件名的标识符,用来做后缀。xxx-{id}.tar.gz。
- formats: 是assembly插件支持的打包文件格式,有zip、tar、tar.gz、tar.bz2、jar、war。可以同时定义多个format。
- fileSets/fileSet: 用来设置一组文件在打包时的属性。
- directory:源目录的路径。
- includes/excludes:设定包含或排除哪些文件,支持通配符。
- fileMode:指定该目录下的文件属性,采用Unix八进制描述法,默认值是0644
- outputDirectory:生成目录的路径。
- files/file: 与fileSets大致相同,不过是指定单个文件,并且还可以通过destName属性来设置与源文件不同的名称。
- dependencySets/dependencySet:用来设置工程依赖文件在打包时的属性。也与fileSets大致相同,不过还有两个特殊的配置:
- unpack:布尔值,false表示将依赖以原来的JAR形式打包,true则表示将依赖解成*.class文件的目录结构打包。
- scope:表示符合哪个作用范围的依赖会被打包进去。compile与provided都不用管,一般是写runtime。
详细使用用法,参见: https://maven.apache.org/plugins/maven-assembly-plugin/assembly.html
FQA
以上问题为,修改了 parent pom 的 属性, 但是 子 pom 没有同步修改导致的出错。
子模块
maven 子模块
子工程中引用那些被父工程管理的依赖
关键点:省略版本号
子工程引用父工程中的依赖信息时,可以把版本号去掉。把版本号去掉就表示子工程中这个依赖的版本由父工程决定,具体来说是由父工程的dependencyManagement来决定。
使用命令行生成 maven 项目工程
mvn archetype:generate -DgroupId=$yourgroupID -DartifactId=$yourartifactID -DarchetypeArtifactId=maven-archetype-quickstart
其中 yourgroupID 即为您的包名。yourartifactID 为您的项目名称,而 maven-archetype-quickstart 表示创建一个 Maven Java 项目。
simple
---pom.xml 核心配置,项目根下
---src
---main
---java Java 源码目录
---resources Java 配置文件目录
---test
---java 测试源码目录
---resources 测试配置目录
然后需要在 pom.xml 中添加打包和编译插件:
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.8</source>
<target>1.8</target>
<encoding>utf-8</encoding>
</configuration>
</plugin>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
<executions>
<execution>
<id>make-assembly</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
自动化格式化代码 mvn plugin
#自动格式化代码
mvn spotless:apply -Pbackends-velox -Prss -Pspark-3.3 -DskipTests