I know you've said you didn't want to create a task, but I would say that's the cleanest way of doing it, so I'll post it as one of the solutions anyway.
Depends on Compile
val printScalaVersion = taskKey[Unit]("Prints Scala version")
printScalaVersion := {
CrossVersion.partialVersion(scalaVersion.value) match {
case Some((2, 11)) => println("2.11")
case Some((2, 10)) => println("2.10")
case _ => println("Other version")
}
}
compile in Compile := ((compile in Compile) dependsOn printScalaVersion).value
Override the Compile Task
If you really wouldn't like to create new task, you could redefine the compile task and add your code there (I think it's not as clean as the solution above).
compile in Compile := {
val analysis = (compile in Compile).value
CrossVersion.partialVersion(scalaVersion.value) match {
case Some((2, 11)) => println("2.11")
case Some((2, 10)) => println("2.10")
case _ => println("Other version")
}
analysis
}