@@ -63,6 +63,15 @@ def java_major_version():
6363 return int (version .split ("." )[0 ])
6464
6565
66+ def kotlin_version_option (version ):
67+ """Return the Maven property for an explicit stable Kotlin version."""
68+ if version is None :
69+ return ""
70+ if re .fullmatch (r"\d+\.\d+\.\d+" , version ) is None :
71+ raise ValueError (f"Invalid Kotlin version: { version } " )
72+ return f"-Dkotlin.version={ version } "
73+
74+
6675def install_java_json (include_jpms = False ):
6776 """Install the Java artifacts consumed by Kotlin JSON modules."""
6877 modules = "fory-json,fory-annotation-processor"
@@ -87,20 +96,24 @@ def install_java_json(include_jpms=False):
8796 )
8897
8998
90- def install_artifacts (include_corpus = True , modules = PRODUCTION_MODULES ):
99+ def install_artifacts (
100+ include_corpus = True , modules = PRODUCTION_MODULES , kotlin_version = None
101+ ):
91102 """Install Kotlin production artifacts and the shared JSON corpus."""
92103 # Artifact consumers need only main JARs. Test stages compile their own test sources later.
104+ version_option = kotlin_version_option (kotlin_version )
93105 common .cd_project_subdir ("kotlin" )
94106 common .exec_cmd (
95107 "mvn -T16 --batch-mode --no-transfer-progress "
96108 f"-pl { modules } -am clean install -Dmaven.test.skip=true "
97- "-Ddokka.skip=true -Dmaven.source.skip=true"
109+ f "-Ddokka.skip=true -Dmaven.source.skip=true { version_option } "
98110 )
99111 if include_corpus :
100112 common .cd_project_subdir ("integration_tests/kotlin_json_corpus" )
101113 common .exec_cmd (
102114 "mvn -T16 --batch-mode --no-transfer-progress clean install "
103- "-Dmaven.test.skip=true -Ddokka.skip=true -Dmaven.source.skip=true"
115+ "-Dmaven.test.skip=true -Ddokka.skip=true -Dmaven.source.skip=true "
116+ f"{ version_option } "
104117 )
105118 verify_corpus_artifact ()
106119
@@ -164,39 +177,45 @@ def _kotlin_version():
164177 return version
165178
166179
167- def run_tests ():
180+ def run_tests (kotlin_version = None ):
168181 """Run the Kotlin JVM matrix for the active JDK."""
169182 logging .info ("Executing fory kotlin tests" )
170183 os .environ .setdefault ("ENABLE_FORY_DEBUG_OUTPUT" , "1" )
171184 major = java_major_version ()
185+ version_option = kotlin_version_option (kotlin_version )
172186 install_java_json (include_jpms = major == 25 )
173187 modules = PRODUCTION_MODULES if major >= 17 else LOW_JDK_MODULES
174- install_artifacts (include_corpus = major >= 17 , modules = modules )
188+ install_artifacts (
189+ include_corpus = major >= 17 ,
190+ modules = modules ,
191+ kotlin_version = kotlin_version ,
192+ )
175193 common .cd_project_subdir ("kotlin" )
176194 if major >= 17 :
177195 common .exec_cmd (
178- "mvn -T16 --batch-mode --no-transfer-progress test -DfailIfNoTests=false"
196+ "mvn -T16 --batch-mode --no-transfer-progress test "
197+ f"-DfailIfNoTests=false { version_option } "
179198 )
180199 common .exec_cmd ("mvn -T16 --batch-mode --no-transfer-progress spotless:check" )
181200 common .cd_project_subdir ("integration_tests/kotlin_json_corpus" )
182201 common .exec_cmd (
183202 "mvn -T16 --batch-mode --no-transfer-progress clean test "
184- "-DfailIfNoTests=false"
203+ f "-DfailIfNoTests=false { version_option } "
185204 )
186205 else :
187206 logging .info (
188207 "Skipping KSP generation tests on JDK < 17 because ksp-maven-plugin requires Java 17+"
189208 )
190209 common .exec_cmd (
191210 "mvn -T16 --batch-mode --no-transfer-progress "
192- f"-pl { LOW_JDK_MODULES } -am test -DfailIfNoTests=false"
211+ f"-pl { LOW_JDK_MODULES } -am test -DfailIfNoTests=false { version_option } "
193212 )
194213 if major == 25 :
195214 common .cd_project_subdir ("kotlin" )
196215 common .exec_cmd (
197216 "mvn -T16 --batch-mode --no-transfer-progress "
198217 f"-pl { PRODUCTION_MODULES } -am package -DskipTests "
199- "-Dgpg.skip=true -Papache-release"
218+ f "-Dgpg.skip=true -Papache-release { version_option } "
200219 )
201220 common .cd_project_subdir ("" )
202221 common .exec_cmd ("python ci/release.py verify_kotlin_artifacts" )
@@ -206,28 +225,34 @@ def run_tests():
206225 logging .info ("Executing fory kotlin tests succeeds" )
207226
208227
209- def run_native_json ():
228+ def run_native_json (kotlin_version = None ):
210229 """Build and execute the dedicated Kotlin JSON Native Image fixture."""
211230 os .environ .setdefault ("ENABLE_FORY_DEBUG_OUTPUT" , "1" )
231+ version_option = kotlin_version_option (kotlin_version )
212232 install_java_json ()
213- install_artifacts (include_corpus = True )
233+ install_artifacts (include_corpus = True , kotlin_version = kotlin_version )
214234 common .cd_project_subdir ("integration_tests/graalvm_kotlin_tests" )
215235 common .exec_cmd (
216- "mvn --batch-mode --no-transfer-progress -DskipTests=true -Pnative clean package"
236+ "mvn --batch-mode --no-transfer-progress -DskipTests=true -Pnative clean package "
237+ f"{ version_option } "
217238 )
218239 common .exec_cmd ("./target/main" )
219240
220241
221- def run (task = "tests" ):
242+ def run (task = "tests" , kotlin_version = None ):
222243 """Run the selected Kotlin CI task."""
223244 if task == "tests" :
224- run_tests ()
245+ run_tests (kotlin_version )
225246 elif task == "install-json" :
226247 install_java_json ()
227- install_artifacts (include_corpus = True , modules = JSON_MODULES )
248+ install_artifacts (
249+ include_corpus = True ,
250+ modules = JSON_MODULES ,
251+ kotlin_version = kotlin_version ,
252+ )
228253 elif task == "install-kotlin" :
229- install_artifacts (include_corpus = True )
254+ install_artifacts (include_corpus = True , kotlin_version = kotlin_version )
230255 elif task == "native-json" :
231- run_native_json ()
256+ run_native_json (kotlin_version )
232257 else :
233258 raise ValueError (f"Unsupported Kotlin CI task: { task } " )
0 commit comments