一般学习 某个框架基本都是从编译源码开始的, 于是那就来吧
首先先clone 官方的源码
https://github.com/apache/zookeeper.git
放到idea 编译
mvn clean package -Dmaven.test.skip=true
这个时候发现抱错了
为什么有个git.properties 比较奇怪
看报错的原因,似乎是有部分代码使用了resources\git.properties文件的配置,但是我们找了一下,在github上的代码中不会存在git.properties,那么是哪里出问题了呢?我们来到pom中找到了
properties-maven-plugin
插件,看到了如下的配置:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>properties-maven-plugin</artifactId>
<executions>
<execution>
<phase>initialize</phase>
<goals>
<goal>read-project-properties</goal>
</goals>
<configuration>
<files>
<file>${basedir}/src/main/resources/git.properties</file>
</files>
</configuration>
</execution>
</executions>
</plugin>
原来是这里初始化的时候会加载该配置文件的内容。
我们可以先注释掉它然后继续编译 发现还是报错了
[INFO] --- exec-maven-plugin:1.6.0:exec (generate-version-info) @ zookeeper ---
Usage: java -cp <classpath> org.apache.zookeeper.version.util.VerGen maj.min.micro[-qualifier] rev buildDate outputDirectory[ERROR] Command execution failed.
org.apache.commons.exec.ExecuteException: Process exited with an error: 1 (Exit value: 1)
at org.apache.commons.exec.DefaultExecutor.executeInternal (DefaultExecutor.java:404)
at org.apache.commons.exec.DefaultExecutor.execute (DefaultExecutor.java:166)
at org.codehaus.mojo.exec.ExecMojo.executeCommandLine (ExecMojo.java:804)
at org.codehaus.mojo.exec.ExecMojo.executeCommandLine (ExecMojo.java:751)
at org.codehaus.mojo.exec.ExecMojo.execute (ExecMojo.java:313)
at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo (DefaultBuildPluginManager.java:137)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:210)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:156)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:148)
at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:117)
at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:81)
at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build (SingleThreadedBuilder.java:56)
at org.apache.maven.lifecycle.internal.LifecycleStarter.execute (LifecycleStarter.java:128)
at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:305)
at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:192)
at org.apache.maven.DefaultMaven.execute (DefaultMaven.java:105)
at org.apache.maven.cli.MavenCli.execute (MavenCli.java:957)
at org.apache.maven.cli.MavenCli.doMain (MavenCli.java:289)
at org.apache.maven.cli.MavenCli.main (MavenCli.java:193)
at sun.reflect.NativeMethodAccessorImpl.invoke0 (Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke (NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke (DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke (Method.java:498)
at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced (Launcher.java:282)
at org.codehaus.plexus.classworlds.launcher.Launcher.launch (Launcher.java:225)
at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode (Launcher.java:406)
at org.codehaus.plexus.classworlds.launcher.Launcher.main (Launcher.java:347)
[INFO] ------------------------------------------------------------------------
[INFO] Reactor Summary for Apache ZooKeeper 3.7.0-SNAPSHOT:
[INFO]
[INFO] Apache ZooKeeper ................................... SUCCESS [ 4.962 s]
[INFO] Apache ZooKeeper - Documentation ................... SUCCESS [ 3.308 s]
[INFO] Apache ZooKeeper - Jute ............................ SUCCESS [ 16.448 s]
[INFO] Apache ZooKeeper - Server .......................... FAILURE [ 2.057 s]
[INFO] Apache ZooKeeper - Metrics Providers ............... SKIPPED
[INFO] Apache ZooKeeper - Prometheus.io Metrics Provider .. SKIPPED
[INFO] Apache ZooKeeper - Client .......................... SKIPPED
[INFO] Apache ZooKeeper - Recipes ......................... SKIPPED
[INFO] Apache ZooKeeper - Recipes - Election .............. SKIPPED
[INFO] Apache ZooKeeper - Recipes - Lock .................. SKIPPED
[INFO] Apache ZooKeeper - Recipes - Queue ................. SKIPPED
[INFO] Apache ZooKeeper - Assembly ........................ SKIPPED
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 27.256 s
[INFO] Finished at: 2020-03-06T18:35:56+08:00
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.codehaus.mojo:exec-maven-plugin:1.6.0:exec (generate-version-info) on project zookeeper: Command execution failed.: Process exited with an error: 1 (Ex
it value: 1) -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
我们还注意到一个插件exec-maven-plugin,里面使用了部分参数在项目中并不存在,应该是引用了git.properties的配置参数导致了pom报错,导致初始化编译失败,如下:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<executions>
<execution>
<id>generate-version-info</id>
<phase>generate-sources</phase>
<goals>
<goal>exec</goal>
</goals>
<configuration>
<workingDirectory>${project.basedir}/src/main/java/</workingDirectory>
<executable>java</executable>
<arguments>
<argument>-classpath</argument>
<classpath />
<argument>org.apache.zookeeper.version.util.VerGen</argument>
<argument>${project.version}</argument>
<argument>${git.commit.id}</argument>
<argument>${build.time}</argument>
<argument>${project.basedir}/target/generated-sources/java</argument>
</arguments>
</configuration>
</execution>
</executions>
</plugin>
我们可以使用一个固定值来替代
git.commit.id
build.time
<argument>ccccccccccc</argument>
<argument>2020-03-01</argument>
再来一次欸发现可以于是大功告成终于迈出了第一步 [苦笑]