Skip to content

Determine the minimum gradle version based on the wrapper #32226

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jul 25, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 5 additions & 8 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -16,21 +16,17 @@
* specific language governing permissions and limitations
* under the License.
*/

import com.github.jengelman.gradle.plugins.shadow.ShadowPlugin
import org.apache.tools.ant.taskdefs.condition.Os
import org.apache.tools.ant.filters.ReplaceTokens
import org.elasticsearch.gradle.BuildPlugin
import org.elasticsearch.gradle.LoggedExec
import org.elasticsearch.gradle.Version
import org.elasticsearch.gradle.VersionCollection
import org.elasticsearch.gradle.VersionProperties
import org.gradle.plugins.ide.eclipse.model.SourceFolder

import org.gradle.api.tasks.wrapper.Wrapper
import org.gradle.api.tasks.wrapper.Wrapper.DistributionType
import org.gradle.util.GradleVersion
import org.gradle.util.DistributionLocator
import org.apache.tools.ant.taskdefs.condition.Os
import org.apache.tools.ant.filters.ReplaceTokens

import java.nio.file.Files
import java.nio.file.Path
Expand Down Expand Up @@ -537,15 +533,16 @@ task run(type: Run) {
}

wrapper {
distributionType = DistributionType.ALL
distributionType = 'ALL'
doLast {
final DistributionLocator locator = new DistributionLocator()
final GradleVersion version = GradleVersion.version(wrapper.gradleVersion)
final URI distributionUri = locator.getDistributionFor(version, wrapper.distributionType.name().toLowerCase(Locale.ENGLISH))
final URI sha256Uri = new URI(distributionUri.toString() + ".sha256")
final String sha256Sum = new String(sha256Uri.toURL().bytes)
wrapper.getPropertiesFile() << "distributionSha256Sum=${sha256Sum}\n"
println "Added checksum to wrapper properties"
wrapper.getPropertiesFile() << "gradleVersion=${gradleVersion}\n"
println "Added checksum and version to wrapper properties"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this println isn't accurate any more, right?

}
}

Expand Down
10 changes: 8 additions & 2 deletions buildSrc/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,13 @@ plugins {

group = 'org.elasticsearch.gradle'

if (GradleVersion.current() < GradleVersion.version('4.9')) {
throw new GradleException('Gradle 4.9+ is required to build elasticsearch')
Properties wrapper = new Properties()
File wrapperProperties = project == rootProject ?
project.file('../gradle/wrapper/gradle-wrapper.properties') :
rootProject.file('gradle/wrapper/gradle-wrapper.properties')
wrapperProperties.withInputStream { wrapper.load(it) }
if (GradleVersion.current() < GradleVersion.version(wrapper.get('gradleVersion'))) {
throw new GradleException("Gradle ${wrapper.get('gradleVersion')}+ is required to build elasticsearch")
}

if (JavaVersion.current() < JavaVersion.VERSION_1_8) {
Expand Down Expand Up @@ -78,6 +83,7 @@ task writeVersionProperties {
processResources {
dependsOn writeVersionProperties
from tempPropertiesFile
from wrapperProperties
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should rename this file so it is more obvious what we are using it for. Or maybe not write the entire file, just the version.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I initially added the file as is thinking about parsing it from the URL, but then realized that the wrapper know about the version it's going to use. In retrospect I'm not sure why I choose to add it to the properties files, I think the initial idea rooted, it makes much more sense to add a minimumGradleVersion resource that just has this version number.

}

/*****************************************************************************
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,13 @@ class BuildPlugin implements Plugin<Project> {
+ 'elasticearch.standalone-rest-test, and elasticsearch.build '
+ 'are mutually exclusive')
}
if (GradleVersion.current() < GradleVersion.version('4.9')) {
throw new GradleException('Gradle 4.9+ is required to use elasticsearch.build plugin')
Properties wrapper = new Properties()
InputStream is = getClass().getResourceAsStream("/gradle-wrapper.properties")
try { wrapper.load(is) } finally { is.close() }
if (GradleVersion.current() < GradleVersion.version(wrapper.get('gradleVersion'))) {
throw new GradleException(
"Gradle ${wrapper.get('gradleVersion')}+ is required to use elasticsearch.build plugin"
)
}
project.pluginManager.apply('java')
project.pluginManager.apply('carrotsearch.randomized-testing')
Expand Down Expand Up @@ -150,14 +155,6 @@ class BuildPlugin implements Plugin<Project> {
}
println " Random Testing Seed : ${project.testSeed}"

// enforce Gradle version
final GradleVersion currentGradleVersion = GradleVersion.current();

final GradleVersion minGradle = GradleVersion.version('4.3')
if (currentGradleVersion < minGradle) {
throw new GradleException("${minGradle} or above is required to build Elasticsearch")
}

// enforce Java version
if (compilerJavaVersionEnum < minimumCompilerVersion) {
final String message =
Expand Down
Binary file modified gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
1 change: 1 addition & 0 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ distributionUrl=https\://services.gradle.org/distributions/gradle-4.9-all.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionSha256Sum=39e2d5803bbd5eaf6c8efe07067b0e5a00235e8c71318642b2ed262920b27721
gradleVersion=4.9
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This won't be in the file if you regenerate it, right?