Skip to content

Commit

Permalink
Merge pull request #1 from augi/DeduceScalaVersion
Browse files Browse the repository at this point in the history
Deduce Scala version
  • Loading branch information
augi authored Oct 15, 2017
2 parents e0d8eaa + a44edd3 commit 569f4d7
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@ class WartremoverPlugin implements Plugin<Project> {
void apply(Project project) {
def extension = project.extensions.create('wartremover', WartremoverExtension)
project.afterEvaluate {
def scalaVersion = getScalaVersion(project)
def configuration = project.configurations.getByName('compileOnly')
project.dependencies.add(configuration.name, 'org.wartremover:wartremover_2.12:2.2.1')
File pluginFile = configuration.resolve().find { it.toString().toLowerCase().contains('wartremover_2.12') && it.toString().toLowerCase().endsWith('.jar') }
project.dependencies.add(configuration.name, "org.wartremover:wartremover_${scalaVersion}:2.2.1")
File pluginFile = configuration.resolve().find { it.toString().toLowerCase().contains("wartremover_${scalaVersion}") && it.toString().toLowerCase().endsWith('.jar') }
if (pluginFile == null) {
throw new RuntimeException('Wartremover JAR cannot be found')
}
Expand All @@ -27,6 +28,15 @@ class WartremoverPlugin implements Plugin<Project> {
}
}

private String getScalaVersion(Project p) {
def scalaLibrary = p.configurations.getByName('compile').dependencies.find { it.group == 'org.scala-lang' && it.name == 'scala-library' }
if (!scalaLibrary) {
p.logger.warn('Scala library dependency not found in \'compile\' configuration, defaulting to 2.12')
return '2.12'
}
scalaLibrary.version.split('\\.').take(2).join('.') // 2.12.3 -> 2.12
}

private String getErrorWartDirective(String name) {
if (!name.contains('.')) {
name = 'org.wartremover.warts.' + name
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ class WartremoverPluginTest extends Specification {
project.repositories {
jcenter()
}
project.dependencies {
compile 'org.scala-lang:scala-library:2.12.3'
}
project.evaluate()
then:
def compileTask = project.tasks.compileScala as ScalaCompile
Expand Down

0 comments on commit 569f4d7

Please sign in to comment.