@@ -103,15 +103,15 @@ abstract class BasePluginTest {
103103 val outputServerShadowJar: JarPath get() = jarPath(" server/build/libs/server-1.0-all.jar" )
104104
105105 fun getDefaultProjectBuildScript (
106- javaPlugin : String = "java",
106+ plugin : String = "java",
107107 withGroup : Boolean = false,
108108 withVersion : Boolean = false,
109109 ): String {
110110 val groupInfo = if (withGroup) " group = 'my'" else " "
111111 val versionInfo = if (withVersion) " version = '1.0'" else " "
112112 return """
113113 plugins {
114- id('$javaPlugin ')
114+ id('$plugin ')
115115 id('com.gradleup.shadow')
116116 }
117117 $groupInfo
@@ -194,26 +194,43 @@ abstract class BasePluginTest {
194194 packageName : String = "my",
195195 withImports : Boolean = false,
196196 className : String = "Main ",
197+ isJava : Boolean = true,
197198 ): String {
198- val imports = if (withImports) " import junit.framework.Test;" else " "
199- val classRef = if (withImports) " \" Refs: \" + Test.class.getName()" else " \" Refs: null\" "
200- path(" src/$sourceSet /java/$packageName /$className .java" ).writeText(
201- """
202- package $packageName ;
203- $imports
204- public class $className {
205- public static void main(String[] args) {
206- if (args.length == 0) {
207- throw new IllegalArgumentException("No arguments provided.");
199+ if (isJava) {
200+ val imports = if (withImports) " import junit.framework.Test;" else " "
201+ val classRef = if (withImports) " \" Refs: \" + Test.class.getName()" else " \" Refs: null\" "
202+ path(" src/$sourceSet /java/$packageName /$className .java" ).writeText(
203+ """
204+ package $packageName ;
205+ $imports
206+ public class $className {
207+ public static void main(String[] args) {
208+ if (args.length == 0) throw new IllegalArgumentException("No arguments provided.");
209+ String content = String.format("Hello, World! (%s) from $className ", (Object[]) args);
210+ System.out.println(content);
211+ System.out.println($classRef );
208212 }
209- String content = String.format("Hello, World! (%s) from $className ", (Object[]) args);
210- System.out.println(content);
211- System.out.println($classRef );
212213 }
213- }
214- """ .trimIndent(),
215- )
216- return packageName.replace(' .' , ' /' ) + " /$className .class"
214+ """ .trimIndent(),
215+ )
216+ } else {
217+ val imports = if (withImports) " import junit.framework.Test;" else " "
218+ val classRef = if (withImports) " \" Refs: \" + Test.class.getName()" else " \" Refs: null\" "
219+ path(" src/$sourceSet /kotlin/$packageName /$className .kt" ).writeText(
220+ """
221+ package $packageName
222+ $imports
223+ fun main(vararg args: String) {
224+ if (args.isEmpty()) throw IllegalArgumentException("No arguments provided.")
225+ val content ="Hello, World! (%s) from $className ".format(*args)
226+ println(content)
227+ println($classRef )
228+ }
229+ """ .trimIndent(),
230+ )
231+ }
232+ val baseClassPath = packageName.replace(' .' , ' /' ) + " /$className "
233+ return if (isJava) " $baseClassPath .class" else " ${baseClassPath} Kt.class"
217234 }
218235
219236 fun writeClientAndServerModules (
0 commit comments