spring-projects-experimental / spring-boot-thin-launcher

Tools for building "thin" executable jars, with a focus on, but not exclusively for, Spring Boot
https://github.com/dsyer/spring-boot-thin-launcher
Apache License 2.0
684 stars 90 forks source link

Proxy settings provided in settings.xml are not used during download #59

Closed cyfax closed 6 years ago

cyfax commented 6 years ago

My settings.xml is basic :

<settings>
  <proxies>
   <proxy>
      <id>example-proxy</id>
      <active>true</active>
      <protocol>https</protocol>
      <host>172.26.132.8</host>
      <port>3128</port>
      <nonProxyHosts>www.google.com|*.example.com</nonProxyHosts>
    </proxy>
  </proxies>
</settings>

Then I run :

java -Dthin.profile=exclude_Shared -Dthin.classpath=path -Dthin.root=. -jar MyJar.jar --thin.dryrun

and I get :

Exception in thread "main" java.lang.reflect.InvocationTargetException
        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.springframework.boot.loader.wrapper.ThinJarWrapper.launch(ThinJarWrapper.java:118)
        at org.springframework.boot.loader.wrapper.ThinJarWrapper.main(ThinJarWrapper.java:90)
Caused by: java.lang.IllegalStateException: hidden.org.eclipse.aether.resolution.ArtifactResolutionException: The following artifacts could not be resolved: ch.qos.logback:logback-core:jar:1.1.11, ch.qos.logback:logback-classic:jar:1.1.11, com.google.code.findbugs:annotations:jar:3.0.1, org.springframework.kafka:spring-kafka:jar:1.3.0.RELEASE, org.springframework:spring-expression:jar:4.3.11.RELEASE, org.springframework:spring-context:jar:4.3.11.RELEASE, org.freemarker:freemarker:jar:2.3.26-incubating, net.jcip:jcip-annotations:jar:1.0, com.fasterxml.jackson.core:jackson-annotations:jar:2.8.0, org.springframework.security:spring-security-core:jar:4.2.3.RELEASE, org.slf4j:jul-to-slf4j:jar:1.7.25, org.springframework:spring-tx:jar:4.3.11.RELEASE, com.fasterxml.jackson.core:jackson-databind:jar:2.8.10, org.slf4j:slf4j-api:jar:1.7.25, org.springframework:spring-web:jar:4.3.11.RELEASE, org.springframework.security:spring-security-config:jar:4.2.3.RELEASE, org.yaml:snakeyaml:jar:1.17, com.sun.mail:dsn:jar:1.5.6, javax.activation:activation:jar:1.1.1, org.springframework:spring-context-support:jar:4.3.11.RELEASE, org.springframework:spring-core:jar:4.3.11.RELEASE, org.springframework:spring-aop:jar:4.3.11.RELEASE, org.slf4j:jcl-over-slf4j:jar:1.7.25, io.jsonwebtoken:jjwt:jar:0.9.0, com.sun.mail:javax.mail:jar:1.5.6, org.springframework.boot:spring-boot-autoconfigure:jar:1.5.7.RELEASE, org.apache.kafka:kafka-clients:jar:0.11.0.1, org.springframework:spring-beans:jar:4.3.11.RELEASE, com.google.code.findbugs:jsr305:jar:3.0.2, com.fasterxml.jackson.datatype:jackson-datatype-jsr310:jar:2.8.10, org.slf4j:log4j-over-slf4j:jar:1.7.25, org.springframework.retry:spring-retry:jar:1.2.1.RELEASE, org.jooq:jool:jar:0.9.12, org.springframework.boot:spring-boot-starter-logging:jar:1.5.7.RELEASE, org.springframework.boot:spring-boot-starter:jar:1.5.7.RELEASE, com.fasterxml.jackson.core:jackson-core:jar:2.8.10, net.jpountz.lz4:lz4:jar:1.3.0, org.springframework.security:spring-security-web:jar:4.2.3.RELEASE, org.springframework.boot:spring-boot-starter-security:jar:1.5.7.RELEASE, org.springframework:spring-messaging:jar:4.3.11.RELEASE, org.springframework.boot:spring-boot-starter-mail:jar:1.5.7.RELEASE, com.google.guava:guava:jar:20.0, org.xerial.snappy:snappy-java:jar:1.1.2.6, org.springframework.boot:spring-boot:jar:1.5.7.RELEASE, io.netty:netty-all:jar:4.1.4.Final: Could not transfer artifact ch.qos.logback:logback-core:jar:1.1.11 from/to spring-snapshots (https://repo.spring.io/libs-snapshot): connect timed out
        at org.springframework.boot.loader.thin.DependencyResolver.collectNonTransitive(DependencyResolver.java:494)
        at org.springframework.boot.loader.thin.DependencyResolver.aetherDependencies(DependencyResolver.java:234)
        at org.springframework.boot.loader.thin.DependencyResolver.dependencies(DependencyResolver.java:182)
        at org.springframework.boot.loader.thin.PathResolver.extract(PathResolver.java:182)
        at org.springframework.boot.loader.thin.PathResolver.resolve(PathResolver.java:94)
        at org.springframework.boot.loader.thin.ThinJarLauncher.getClassPathArchives(ThinJarLauncher.java:320)
        at org.springframework.boot.loader.thin.ThinJarLauncher.launch(ThinJarLauncher.java:169)
        at org.springframework.boot.loader.thin.ThinJarLauncher.main(ThinJarLauncher.java:133)
        ... 6 more
Caused by: hidden.org.eclipse.aether.resolution.ArtifactResolutionException: The following artifacts could not be resolved: ch.qos.logback:logback-core:jar:1.1.11, ch.qos.logback:logback-classic:jar:1.1.11, com.google.code.findbugs:annotations:jar:3.0.1, org.springframework.kafka:spring-kafka:jar:1.3.0.RELEASE, org.springframework:spring-expression:jar:4.3.11.RELEASE, org.springframework:spring-context:jar:4.3.11.RELEASE, org.freemarker:freemarker:jar:2.3.26-incubating, net.jcip:jcip-annotations:jar:1.0, com.fasterxml.jackson.core:jackson-annotations:jar:2.8.0, org.springframework.security:spring-security-core:jar:4.2.3.RELEASE, org.slf4j:jul-to-slf4j:jar:1.7.25, org.springframework:spring-tx:jar:4.3.11.RELEASE, com.fasterxml.jackson.core:jackson-databind:jar:2.8.10, org.slf4j:slf4j-api:jar:1.7.25, org.springframework:spring-web:jar:4.3.11.RELEASE, org.springframework.security:spring-security-config:jar:4.2.3.RELEASE, org.yaml:snakeyaml:jar:1.17, com.sun.mail:dsn:jar:1.5.6, javax.activation:activation:jar:1.1.1, org.springframework:spring-context-support:jar:4.3.11.RELEASE, org.springframework:spring-core:jar:4.3.11.RELEASE, org.springframework:spring-aop:jar:4.3.11.RELEASE, org.slf4j:jcl-over-slf4j:jar:1.7.25, io.jsonwebtoken:jjwt:jar:0.9.0, com.sun.mail:javax.mail:jar:1.5.6, org.springframework.boot:spring-boot-autoconfigure:jar:1.5.7.RELEASE, org.apache.kafka:kafka-clients:jar:0.11.0.1, org.springframework:spring-beans:jar:4.3.11.RELEASE, com.google.code.findbugs:jsr305:jar:3.0.2, com.fasterxml.jackson.datatype:jackson-datatype-jsr310:jar:2.8.10, org.slf4j:log4j-over-slf4j:jar:1.7.25, org.springframework.retry:spring-retry:jar:1.2.1.RELEASE, org.jooq:jool:jar:0.9.12, org.springframework.boot:spring-boot-starter-logging:jar:1.5.7.RELEASE, org.springframework.boot:spring-boot-starter:jar:1.5.7.RELEASE, com.fasterxml.jackson.core:jackson-core:jar:2.8.10, net.jpountz.lz4:lz4:jar:1.3.0, org.springframework.security:spring-security-web:jar:4.2.3.RELEASE, org.springframework.boot:spring-boot-starter-security:jar:1.5.7.RELEASE, org.springframework:spring-messaging:jar:4.3.11.RELEASE, org.springframework.boot:spring-boot-starter-mail:jar:1.5.7.RELEASE, com.google.guava:guava:jar:20.0, org.xerial.snappy:snappy-java:jar:1.1.2.6, org.springframework.boot:spring-boot:jar:1.5.7.RELEASE, io.netty:netty-all:jar:4.1.4.Final: Could not transfer artifact ch.qos.logback:logback-core:jar:1.1.11 from/to spring-snapshots (https://repo.spring.io/libs-snapshot): connect timed out
        at hidden.org.eclipse.aether.internal.impl.DefaultArtifactResolver.resolve(DefaultArtifactResolver.java:444)
        at hidden.org.eclipse.aether.internal.impl.DefaultArtifactResolver.resolveArtifacts(DefaultArtifactResolver.java:246)
        at hidden.org.eclipse.aether.internal.impl.DefaultRepositorySystem.resolveArtifacts(DefaultRepositorySystem.java:302)
        at org.springframework.boot.loader.thin.DependencyResolver.collectNonTransitive(DependencyResolver.java:490)
        ... 13 more
Caused by: hidden.org.eclipse.aether.transfer.ArtifactTransferException: Could not transfer artifact ch.qos.logback:logback-core:jar:1.1.11 from/to spring-snapshots (https://repo.spring.io/libs-snapshot): connect timed out
        at hidden.org.eclipse.aether.connector.basic.ArtifactTransportListener.transferFailed(ArtifactTransportListener.java:43)
        at hidden.org.eclipse.aether.connector.basic.BasicRepositoryConnector$TaskRunner.run(BasicRepositoryConnector.java:355)
        at hidden.org.eclipse.aether.util.concurrency.RunnableErrorForwarder$1.run(RunnableErrorForwarder.java:67)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
        at java.lang.Thread.run(Thread.java:745)
Caused by: java.net.SocketTimeoutException: connect timed out
        at java.net.PlainSocketImpl.socketConnect(Native Method)
        at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:350)
        at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:206)
        at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:188)
        at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)
        at java.net.Socket.connect(Socket.java:589)
        at org.apache.http.conn.ssl.SSLSocketFactory.connectSocket(SSLSocketFactory.java:542)
        at org.apache.http.conn.ssl.SSLSocketFactory.connectSocket(SSLSocketFactory.java:414)
        at org.apache.http.impl.conn.DefaultClientConnectionOperator.openConnection(DefaultClientConnectionOperator.java:180)
        at org.apache.http.impl.conn.ManagedClientConnectionImpl.open(ManagedClientConnectionImpl.java:326)
        at org.apache.http.impl.client.DefaultRequestDirector.tryConnect(DefaultRequestDirector.java:610)
        at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:445)
        at org.apache.http.impl.client.AbstractHttpClient.doExecute(AbstractHttpClient.java:835)
        at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:72)
        at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:56)
        at org.apache.http.impl.client.DecompressingHttpClient.execute(DecompressingHttpClient.java:164)
        at hidden.org.eclipse.aether.transport.http.HttpTransporter.execute(HttpTransporter.java:287)
        at hidden.org.eclipse.aether.transport.http.HttpTransporter.implGet(HttpTransporter.java:243)
        at hidden.org.eclipse.aether.spi.connector.transport.AbstractTransporter.get(AbstractTransporter.java:59)
        at hidden.org.eclipse.aether.connector.basic.BasicRepositoryConnector$GetTaskRunner.runTask(BasicRepositoryConnector.java:447)
        at hidden.org.eclipse.aether.connector.basic.BasicRepositoryConnector$TaskRunner.run(BasicRepositoryConnector.java:350)
        ... 4 more

This is my analysis :

In lines 125 & 138 of https://github.com/eclipse/aether-core/blob/4cf5f7a406b516a45d8bf15e7dfe3fb3849cb87b/aether-transport-http/src/main/java/org/eclipse/aether/transport/http/HttpTransporter.java#L125 we can see httpclient proxy is configured from RemoteRepository.proxy

And from https://github.com/dsyer/spring-boot-thin-launcher/blob/561d2e4b8a17addfbba75d4bfca36f4dd3cde4f8/launcher/src/main/java/org/springframework/boot/loader/thin/DependencyResolver.java#L359 we can see builder is not invoking setProxy method (https://github.com/eclipse/aether-core/blob/4cf5f7a406b516a45d8bf15e7dfe3fb3849cb87b/aether-api/src/main/java/org/eclipse/aether/repository/RemoteRepository.java#L472)

in conjunction of https://github.com/dsyer/spring-boot-thin-launcher/blob/561d2e4b8a17addfbba75d4bfca36f4dd3cde4f8/launcher/src/main/java/org/springframework/boot/loader/thin/MavenSettings.java#L255

Thank you for taking time to see whether my analysis is good.

dsyer commented 6 years ago

Is that fixed now?

cyfax commented 6 years ago

Hello. I do not know how to proceed.

This my plan:

  1. Clone the git repo
  2. run a ./mvnw clean install
  3. Generate my bootJar with the new plugin
  4. Launch myj bootJar with proxy settings.

I do not know how to do step 3. In my build.gradle file I have

buildscript {
    ext {
        springBootVersion = '2.0.3.RELEASE'
        wrapperVersion = '1.0.12.RELEASE'
    }
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
        classpath("org.springframework.boot.experimental:spring-boot-thin-gradle-plugin:${wrapperVersion}")
    }

I do not know how to specify a non maven available plugin/dependency. Do you have a hint ?

dsyer commented 6 years ago

That's not really a question about this project, and I don't know enough Gradle to help you. Try looking at the samples in this repo. Or use Maven.

Note that snapshots are published to repo.spring.io, so you don't need to build locally (but it won't hurt).

cyfax commented 6 years ago

Hello. I did not know there was public snapshot repository. The gradle config was obvious (add snapshot repo and change dependency version) :

buildscript {
    ext {
        springBootVersion = '2.0.3.RELEASE'
        wrapperVersion = '1.0.14.BUILD-20180814.125412-3'
    }
    repositories {
        mavenCentral()
        maven { url "https://repo.spring.io/snapshot" }
    }
    dependencies {
        classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
        classpath("org.hidetake:gradle-ssh-plugin:2.9.0")
        classpath("org.springframework.boot.experimental:spring-boot-thin-gradle-plugin:${wrapperVersion}")
    }

The fix is working fine. There is only one subtle thing to note.

ThinJarWrapper does not use Maven mecanism to download artifact : https://github.com/dsyer/spring-boot-thin-launcher/blob/a6da361db954f178018f4e6c37144ec4114c44c7/wrapper/src/main/java/org/springframework/boot/loader/wrapper/ThinJarWrapper.java#L307

So you must specify -D args for networking as well : cf. https://docs.oracle.com/javase/8/docs/api/java/net/doc-files/net-properties.html

to download org.springframework.boot.experimental:spring-boot-thin-launcher:jar:exec:1.0.14.BUILD-SNAPSHOT.

I guess a little doc would be enough. Would you please make a release with this fix ? Regards cyfax

dsyer commented 6 years ago

1.0.14 should be available now (as soon as the artifacts are synched with Maven Central).