开发者构建工具

Maven,SBT构建工具

Maven

assembly

maven-assembly-plugin

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
<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>

maven-shade-plugin

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>2.4.3</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>
shade
</goal>
</goals>
</execution>
</executions>
<configuration>
<minimizeJar>true</minimizeJar>
<shadedArtifactAttached>true</shadedArtifactAttached>
<shadedClassifierName>fat</shadedClassifierName>
<relocations>
<relocation>
<pattern>com.google</pattern>
<shadedPattern>shaded.guava</shadedPattern>
<includes>
<include>com.google.**</include>
</includes>
<excludes>
<exclude>com.google.common.base.Optional</exclude>
<exclude>com.google.common.base.Absent</exclude>
<exclude>com.google.common.base.Present</exclude>
</excludes>
</relocation>
</relocations>
<filters>
<filter>
<artifact>*:*</artifact>
<excludes>
<exclude>META-INF/*.SF</exclude>
<exclude>META-INF/*.DSA</exclude>
<exclude>META-INF/*.RSA</exclude>
</excludes>
</filter>
</filters>
</configuration>
</plugin>
1
2
3
4
5
6
7
8
9
10
11
[INFO] --- maven-jar-plugin:2.4:jar (default-jar) @ test ---
[INFO] Building jar: /Users/zhengqh/Github/test/target/test-1.0-SNAPSHOT.jar
[INFO] --- maven-assembly-plugin:2.2-beta-5:single (make-assembly) @ test ---
...
[INFO] Building jar: /Users/zhengqh/Github/test/target/test-1.0-SNAPSHOT-jar-with-dependencies.jar
[INFO] Minimizing jar test:test:jar:1.0-SNAPSHOT

$ ll target
-rw-r--r-- 1 zhengqh staff 8.1M 6 22 11:54 test-1.0-SNAPSHOT-fat.jar
-rw-r--r-- 1 zhengqh staff 29M 6 22 11:54 test-1.0-SNAPSHOT-jar-with-dependencies.jar
-rw-r--r-- 1 zhengqh staff 9.2K 6 22 11:54 test-1.0-SNAPSHOT.jar

maven-assembly-plugin生成test-1.0-SNAPSHOT-jar-with-dependencies.jar
maven-shade-plugin的shadedClassifierName为fat,结果:test-1.0-SNAPSHOT-fat.jar

1
2
3
4
5
6
7
8
➜  test jar -tvf target/test-1.0-SNAPSHOT-jar-with-dependencies.jar|grep shaded
assembly并不会重命令,只有shade才可以

➜ test jar -tvf target/test-1.0-SNAPSHOT-fat.jar|grep shaded
0 Thu Jun 22 11:54:42 CST 2017 shaded/
0 Thu Jun 22 11:54:42 CST 2017 shaded/guava/
0 Thu Jun 22 11:54:42 CST 2017 shaded/guava/common/
...

install

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
mvn install:install-file -Dfile=~/Downloads/ojdbc6-11.2.0.3.jar -DgroupId=com.oracle -DartifactId=ojdbc6 -Dversion=11.2.0 -Dpackaging=jar

mvn install:install-file -Dfile=pontus-api_2.11-0.0.1.jar -DgroupId=cn.fraudmetrix.pontus -DartifactId=pontus-api_2.11 -Dversion=0.0.1 -Dpackaging=jar

[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building Maven Stub Project (No POM) 1
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-install-plugin:2.4:install-file (default-cli) @ standalone-pom ---
[INFO] Installing /Users/zhengqh/pontus-api_2.11-0.0.1.jar to /Users/zhengqh/.m2/repository/cn/fraudmetrix/pontus/pontus-api_2.11/0.0.1/pontus-api_2.11-0.0.1.jar
[INFO] Installing /var/folders/xc/x0b8crk9667ddh1zhfs29_zr0000gn/T/mvninstall1940592568391629100.pom to /Users/zhengqh/.m2/repository/cn/fraudmetrix/pontus/pontus-api_2.11/0.0.1/pontus-api_2.11-0.0.1.pom
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1.088 s
[INFO] Finished at: 2017-07-17T11:50:49+08:00
[INFO] Final Memory: 6M/64M
[INFO] ------------------------------------------------------------------------

deploy

源码包上传

1
mvn deploy

本地包上传到nexus

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
mvn deploy:deploy-file -DgroupId=<group-id> \
-DartifactId=<artifact-id> \
-Dversion=<version> \
-Dpackaging=<type-of-packaging> \
-Dfile=<path-to-file> \
-DrepositoryId=<id-to-map-on-server-section-of-settings.xml> \
-Durl=<url-of-the-repository-to-deploy>

mvn deploy:deploy-file -DgroupId=依赖项的GroupID \
-DartifactId=依赖项名称 \
-Dversion=依赖版本 \
-Dpackaging=jar \
-Dfile=三方库的文件路径 \
-DrepositoryId=fraudmetrixRepo \
-Durl=http://maven.fraudmetrix.cn/nexus/content/repositories/releases/

repositoryId对应~/.m2/setting.xml中的server配置

<server>
<id>fraudmetrixRepo</id>
<username>xxx</username>
<password>xxx</password>
</server>

部署pontus-api.jar
mvn deploy:deploy-file -DgroupId=cn.fraudmetrix.pontus -DartifactId=pontus-api_2.11 -Dversion=0.0.1 \
-Dpackaging=jar -Dfile=pontus-api_2.11-0.0.1.jar \
-Durl=http://maven.fraudmetrix.cn/nexus/content/repositories/releases/ -DrepositoryId=fraudmetrixRepo

部署ojdbc.jar
mvn deploy:deploy-file -Dfile=/Users/zhengqh/Downloads/install/ojdbc6-11.2.0.3.jar \
-DgroupId=com.oracle -DartifactId=ojdbc6 -Dversion=11.2.0 -Dpackaging=jar \
-Durl=http://maven.fraudmetrix.cn/nexus/content/repositories/releases/ -DrepositoryId=fraudmetrixRepo

以-数字开头或者-V开头生成准备文件:

1
2
3
4
5
6
7
val files = new java.io.File("/Users/zhengqh/Downloads/V100R002C60U20CP003/common/lib").listFiles.map(_.getName).filter(_.startsWith("h")).toList
import scala.util.matching.Regex
val numitemPattern = "(.*)(-[0-9|V].*)".r
files.foreach(file => {
val numitemPattern(art, version) = file
println(file + " " + art + " " + version.substring(1).replace(".jar",""))
})

导入到maven仓库:

1
2
3
4
5
6
7
8
9
10
cat genMaven.txt | while read line
do
jar=`echo $line | cut -d" " -f1`
art=`echo $line | cut -d" " -f2`
ver=`echo $line | cut -d" " -f3`
echo "$jar $art $ver"
mvn deploy:deploy-file -Dfile=$jar \
-DgroupId=com.huawei.fusion -DartifactId=$art -Dversion="$ver-FSV100R002C60U20CP003" -Dpackaging=jar \
-Durl=http://maven.fraudmetrix.cn/nexus/content/repositories/releases/ -DrepositoryId=fraudmetrixRepo
done

不更改groupId,从MANIFEST中获取groupId

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
cat genMaven.txt | while read line
do
jarName=`echo $line | cut -d" " -f1`
art=`echo $line | cut -d" " -f2`
ver=`echo $line | cut -d" " -f3`
printf "$jarName $art $ver "
jar xf $jarName META-INF/MANIFEST.MF
group=$(cat META-INF/MANIFEST.MF |grep Implementation-Vendor-Id |cut -d" " -f2)
if [ -n "$group" ]; then
printf "$group"
print
fi
rm -rf META-INF
done

cat genFS.txt | while read line
do
jarName=`echo $line | cut -d" " -f1`
art=`echo $line | cut -d" " -f2`
ver=`echo $line | cut -d" " -f3`
group=`echo $line | cut -d" " -f4`
echo "$jarName $art $ver $group"
mvn deploy:deploy-file -Dfile=$jarName \
-DgroupId=$group -DartifactId=$art -Dversion="$ver-FSV100R002C60U20CP003" -Dpackaging=jar \
-Durl=http://maven.fraudmetrix.cn/nexus/content/repositories/releases/ -DrepositoryId=fraudmetrixRepo
done

找不到的jar包改版本后重新上传

1
2
3
4
5
mvn deploy:deploy-file -Dfile=hadoop-yarn-server-tests-2.7.2.jar \
-DgroupId=org.apache.hadoop -DartifactId=hadoop-yarn-server-tests -Dversion=2.7.2-FSV100R002C60U20CP003 -Dpackaging=jar \
-Durl=http://maven.fraudmetrix.cn/nexus/content/repositories/releases/ -DrepositoryId=fraudmetrixRepo

find ~/.m2/ -name "*.lastUpdated" | xargs rm

SBT

Ref


文章目录
  1. 1. Maven
    1. 1.1. assembly
    2. 1.2. install
    3. 1.3. deploy
  2. 2. SBT
  3. 3. Ref