-1

I clone the code from https://github.com/square/okhttp

And I want to read the source code of 3.10.0 version.

But it could not compile successfully.

gongzelong:okhttp gongzelong$ git branch
  master
* parent-3.10.0
gongzelong:okhttp gongzelong$ mvn clean verify
[INFO] Scanning for projects...
[ERROR] [ERROR] Some problems were encountered while processing the POMs:
[ERROR] 'build.plugins.plugin[org.apache.maven.plugins:maven-surefire-plugin].dependencies.dependency.version' for org.mortbay.jetty.alpn:alpn-boot:jar must be a valid version but is '${alpn.jdk8.version}'. @ com.squareup.okhttp3:parent:3.10.0, /Users/gongzelong/Android/okhttp/pom.xml, line 320, column 28
 @ 
[ERROR] The build could not read 1 project -> [Help 1]
[ERROR]   
[ERROR]   The project com.squareup.okhttp3:okhttp:3.10.0 (/Users/gongzelong/Android/okhttp/okhttp/pom.xml) has 1 error
[ERROR]     'build.plugins.plugin[org.apache.maven.plugins:maven-surefire-plugin].dependencies.dependency.version' for org.mortbay.jetty.alpn:alpn-boot:jar must be a valid version but is '${alpn.jdk8.version}'. @ com.squareup.okhttp3:parent:3.10.0, /Users/gongzelong/Android/okhttp/pom.xml, line 320, column 28
[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.
[ERROR] 
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/ProjectBuildingException

After adding the code which is in my answer, it could run 'mvn clean verify'

But IDEA shows error like this:

enter image description here enter image description here enter image description here

Francis Bacon
  • 4,080
  • 1
  • 37
  • 48

3 Answers3

3

You can also add that library to a demo project, the in android studio changes it to Project folder. you can find it in the external libraries.

or you can download it, then use the VsCode editor to open it and read.

Lenoarod
  • 3,441
  • 14
  • 25
  • It is an option, but why the problem occurs and how to fix it directly? – Francis Bacon Dec 30 '19 at 08:08
  • 1
    you can try isaaaaame answer. but the OkHttp is a pure library if you use the android studio open it, you have to use import module or add library method. – Lenoarod Dec 30 '19 at 08:27
3

for org.mortbay.jetty.alpn:alpn-boot:jar must be a valid version but is '${alpn.jdk8.version}'

in their build.gradle they have

def alpnBootVersion() {
def version = System.getProperty('alpn.boot.version')

if (version != null) {
  return version
}

They have probably added alpn.jdk8.version as a variable in their local gradle.properties. Change def version = System.getProperty('alpn.boot.version') with def version = 8.1.13 , and this should solve the problem.

isaaaaame
  • 460
  • 4
  • 9
  • The codes you mentions belongs to the version 3.10.0? It seems that there are no such codes in 3.10.0 – Francis Bacon Dec 30 '19 at 09:33
  • @FrancisBacon check their build.gradle, it was edited 8 days ago: https://github.com/square/okhttp/blob/master/build.gradle – isaaaaame Dec 30 '19 at 09:36
  • What you mean is trying to build the latest source code of okhttp. But how to build 3.10.0 source codes? – Francis Bacon Dec 30 '19 at 09:38
  • as @Lenoarod said: "OkHttp is a pure library if you use the android studio open it, you have to use import module or add library method.". it's not meant to be build as a standalone project. – isaaaaame Dec 30 '19 at 09:44
  • I opened in via IDEA, so I should compile the project using maven. And the CONTRIBUTE.MD said, it could run 'mvn clean verify' successfully. – Francis Bacon Dec 30 '19 at 09:56
0

It is due to lack of alpn version regarding to my java version

gongzelong:okhttp gongzelong$ java -version java version "1.8.0_172" Java(TM) SE Runtime Environment (build 1.8.0_172-b11) Java HotSpot(TM) 64-Bit Server VM (build 25.172-b11, mixed mode)

So after I add the following codes in the file /Users/gongzelong/Android/okhttp/pom.xml

gongzelong:okhttp gongzelong$ git diff
diff --git a/pom.xml b/pom.xml
index 8b87c2038..274159c3e 100644
--- a/pom.xml
+++ b/pom.xml
@@ -620,5 +620,14 @@
         <alpn.jdk8.version>8.1.12.v20180117</alpn.jdk8.version>
       </properties>
     </profile>
+    <profile>
+      <id>alpn-when-jdk8_172</id>
+      <activation>
+        <jdk>1.8.0_172</jdk>
+      </activation>
+      <properties>
+        <alpn.jdk8.version>8.1.12.v20180117</alpn.jdk8.version>
+      </properties>
+    </profile>
   </profiles>
 </project>

It could run 'mvn clean verify' and 'mvn clean install'.

Francis Bacon
  • 4,080
  • 1
  • 37
  • 48