buildship icon indicating copy to clipboard operation
buildship copied to clipboard

Can't configure the truststore with an relative path in gradle.properties

Open chkpnt opened this issue 3 years ago • 4 comments
trafficstars

I'm using a Nexus repository server for my dependencies, for which I need a truststore with the corresponding CA certificate. This truststore shall be part of the project, so the project can be built out-of-the-box without configuring ~/.gradle/gradle.properties.

Therefore I'm using the following gradle.properties within my project with a relative path to my truststore, whereas ./gradle/truststore.jks is part of the project, too:

...
systemProp.javax.net.ssl.trustStore=./gradle/truststore.jks
systemProp.javax.net.ssl.trustStorePassword=changeit
...

This works well when using Gradle from the command line, but as Buildship is using ~/.gradle/daemon/<version>/ as the working directory, it doesn't work using Eclipse.

Expected Behavior

No difference between Buildship and using ./gradlew.

Current Behavior

I'm getting the following error when refreshing the Gradle project in Eclipse and some dependencies are not cached yet:

...
Could not resolve all files for configuration ':buildSrc:compileClasspath'.
Could not resolve org.ajoberstar.grgit:grgit-core:4.1.1.
Required by:
    project :buildSrc
Could not resolve org.ajoberstar.grgit:grgit-core:4.1.1.
Could not get resource 'https://<nexus-server>/repository/maven-public/org/ajoberstar/grgit/grgit-core/4.1.1/grgit-core-4.1.1.pom'.
org.apache.http.ssl.SSLInitializationException: ./gradle/truststore.jks (No such file or directory)
./gradle/truststore.jks (No such file or directory)

Executing ./gradlew build works well: The dependencies are loaded from <nexus-server> for which ./gradle/truststore.jks is loaded.

Context

see description above This issue is unrelated to #337, which is about the working directory in launcher configurations.

Steps to Reproduce

  1. set systemProp.javax.net.ssl.trustStore to a truststore using a relative path
  2. delete cache
  3. import / refresh Gradle project in Eclipse

Your Environment

  • macOS Big Sur
  • Eclipse 2021-03
  • Buildship 3.1.5.v20210113-0929
  • Java 11
  • Gradle 7.4.2

chkpnt avatar Apr 06 '22 10:04 chkpnt

A workaround is to set the truststore to an absolute path by a custom task during project evaluation:

# build.gradle

task configureTrustStore {
    System.setProperty("javax.net.ssl.trustStore", "${projectDir}/gradle/truststore.jks")
    System.setProperty("javax.net.ssl.trustStorePassword", "changeit")
}

chkpnt avatar Apr 06 '22 12:04 chkpnt

When the kotlin-dsl plugin is used and the dependencies aren't loaded yet (--refresh-dependencies), the (custom) plugin repositories are contacted before the properties are set. So setting the properties in the project evaluation as show above is to late. Instead, you can configure the Java properties in the pluginManagement-block:

# settings.gradle(.kts)

pluginManagement {
    repositories {
        maven(url = "https://repo.example.com/repository/gradle-plugins/")
    }

    // Can't be set via gradle.properties, as it doesn't work in Eclipse, see https://github.com/eclipse/buildship/issues/1145
    System.setProperty("javax.net.ssl.trustStore", "${rootDir}/gradle/truststore.jks")
    System.setProperty("javax.net.ssl.trustStorePassword", "changeit")
}

For more information, see https://discuss.gradle.org/t/gradle-core-plugin-isnt-loaded-from-custom-repository/47297/5?u=chkpnt

chkpnt avatar Jan 11 '24 15:01 chkpnt