Skip to content

Commit

Permalink
don't use string comparisons for version checks
Browse files Browse the repository at this point in the history
  • Loading branch information
jonabc committed Feb 21, 2023
1 parent 4797fc5 commit 84731f3
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions lib/licensed/sources/gradle.rb
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ def run(command)
args = [command]
# The configuration cache is an incubating feature that can be activated manually.
# The gradle plugin for licenses does not support it so we prevent it to run for gradle version supporting it.
args << "--no-configuration-cache" if gradle_version >= "6.6"
args << "--no-configuration-cache" if gradle_version >= Gem::Version.new("6.6")
Licensed::Shell.execute(@executable, "-q", "--init-script", @init_script.path, *args)
end

Expand All @@ -164,7 +164,7 @@ def create_init_script(configurations)
}
}
dependencies {
classpath "com.github.jk1:gradle-license-report:#{gradle_version >= "7.0" ? "2.0" : "1.17"}"
classpath "com.github.jk1:gradle-license-report:#{gradle_version >= Gem::Version.new("7.0") ? "2.0" : "1.17"}"
}
}
Expand Down Expand Up @@ -195,6 +195,14 @@ def id = artifact.moduleVersion.id
f.close
f
end

# Returns the version of gradle used during execution
def gradle_version
@gradle_version ||= begin
version = Licensed::Shell.execute(@executable, "--version").scan(/Gradle [\d+]\.[\d+]/).last.split(" ").last
Gem::Version.new(version)
end
end
end
end
end
Expand Down

0 comments on commit 84731f3

Please sign in to comment.