@@ -86,12 +86,13 @@ public interface Scalafix {
86
86
* <p>
87
87
* The custom classloader optionally provided with {@link ScalafixArguments#withToolClasspath} to compile and
88
88
* classload external rules must have the classloader of the returned instance as ancestor to share a common
89
- * loaded instance of `scalafix-core`, and therefore have been compiled against the requested Scala binary version.
89
+ * loaded instance of `scalafix-core`, and therefore have been compiled against the requested Scala version.
90
90
*
91
- * @param requestedScalaVersion The Scala version ("3.3.4" for example) available in the classloader of the
91
+ * @param requestedScalaVersion A full Scala version (i.e. "3.3.4") or a major.minor one (i.e. "3.3") to infer
92
+ * the major.minor Scala version that should be available in the classloader of the
92
93
* returned instance. To be able to run advanced semantic rules using the Scala
93
- * Presentation Compiler such as ExplicitResultTypes, this must match the version
94
- * that the target classpath was built with, as provided with
94
+ * Presentation Compiler such as ExplicitResultTypes, this must be source-compatible
95
+ * with the version that the target classpath is built with, as provided with
95
96
* {@link ScalafixArguments#withScalaVersion}.
96
97
* @return An implementation of the {@link Scalafix} interface.
97
98
* @throws ScalafixException in case of errors during artifact resolution/fetching.
@@ -106,12 +107,13 @@ static Scalafix fetchAndClassloadInstance(String scalaBinaryVersion) throws Scal
106
107
* <p>
107
108
* The custom classloader optionally provided with {@link ScalafixArguments#withToolClasspath} to compile and
108
109
* classload external rules must have the classloader of the returned instance as ancestor to share a common
109
- * loaded instance of `scalafix-core`, and therefore have been compiled against the requested Scala binary version.
110
+ * loaded instance of `scalafix-core`, and therefore have been compiled against the requested Scala version.
110
111
*
111
- * @param requestedScalaVersion The Scala version ("3.3.4" for example) available in the classloader of the
112
+ * @param requestedScalaVersion A full Scala version (i.e. "3.3.4") or a major.minor one (i.e. "3.3") to infer
113
+ * the major.minor Scala version that should be available in the classloader of the
112
114
* returned instance. To be able to run advanced semantic rules using the Scala
113
- * Presentation Compiler such as ExplicitResultTypes, this must match the version
114
- * that the target classpath was built with, as provided with
115
+ * Presentation Compiler such as ExplicitResultTypes, this must be source-compatible
116
+ * with the version that the target classpath is built with, as provided with
115
117
* {@link ScalafixArguments#withScalaVersion}.
116
118
* @param repositories Maven/Ivy repositories to fetch the JARs from.
117
119
* @return An implementation of the {@link Scalafix} interface.
@@ -120,17 +122,21 @@ static Scalafix fetchAndClassloadInstance(String scalaBinaryVersion) throws Scal
120
122
static Scalafix fetchAndClassloadInstance (String requestedScalaVersion , List <Repository > repositories )
121
123
throws ScalafixException {
122
124
125
+ String requestedScalaMajorMinorOrMajorVersion =
126
+ requestedScalaVersion .replaceAll ("^(\\ d+\\ .\\ d+).*" , "$1" );
127
+
123
128
String scalaVersionKey ;
124
- if (requestedScalaVersion . startsWith ("2.12" )) {
129
+ if (requestedScalaMajorMinorOrMajorVersion . equals ("2.12" )) {
125
130
scalaVersionKey = "scala212" ;
126
- } else if (requestedScalaVersion .startsWith ("2.13" )) {
131
+ } else if (requestedScalaMajorMinorOrMajorVersion .equals ("2.13" ) ||
132
+ requestedScalaMajorMinorOrMajorVersion .equals ("2" )) {
127
133
scalaVersionKey = "scala213" ;
128
- } else if (requestedScalaVersion . startsWith ("3.0" ) ||
129
- requestedScalaVersion . startsWith ("3.1" ) ||
130
- requestedScalaVersion . startsWith ("3.2" ) ||
131
- requestedScalaVersion . startsWith ("3.3" )) {
134
+ } else if (requestedScalaMajorMinorOrMajorVersion . equals ("3.0" ) ||
135
+ requestedScalaMajorMinorOrMajorVersion . equals ("3.1" ) ||
136
+ requestedScalaMajorMinorOrMajorVersion . equals ("3.2" ) ||
137
+ requestedScalaMajorMinorOrMajorVersion . equals ("3.3" )) {
132
138
scalaVersionKey = "scala3LTS" ;
133
- } else if (requestedScalaVersion .startsWith ("3" )) {
139
+ } else if (requestedScalaMajorMinorOrMajorVersion .startsWith ("3" )) {
134
140
scalaVersionKey = "scala3Next" ;
135
141
} else {
136
142
throw new IllegalArgumentException ("Unsupported scala version " + requestedScalaVersion );
0 commit comments