diff --git a/ant/src/org/jetbrains/kotlin/ant/Kotlin2JvmTask.kt b/ant/src/org/jetbrains/kotlin/ant/Kotlin2JvmTask.kt
index 5bd28044cda..b0fa7bf1b8b 100644
--- a/ant/src/org/jetbrains/kotlin/ant/Kotlin2JvmTask.kt
+++ b/ant/src/org/jetbrains/kotlin/ant/Kotlin2JvmTask.kt
@@ -70,6 +70,14 @@ public class Kotlin2JvmTask : KotlinCompilerBaseTask() {
args.add(it.list().join(pathSeparator))
}
+ if (moduleName == null) {
+ if (owningTarget != null) {
+ moduleName = owningTarget.name
+ } else {
+ moduleName = getProject().name
+ }
+ }
+
moduleName?.let {
args.add("-module-name")
args.add(moduleName!!)
diff --git a/compiler/testData/integration/ant/jvm/moduleName/build.log.expected b/compiler/testData/integration/ant/jvm/moduleName/build.log.expected
new file mode 100644
index 00000000000..f3ebd0b0a4f
--- /dev/null
+++ b/compiler/testData/integration/ant/jvm/moduleName/build.log.expected
@@ -0,0 +1,11 @@
+OUT:
+Buildfile: [TestData]/build.xml
+
+build:
+ [kotlinc] Compiling [[TestData]/hello.kt] => [[Temp]/hello.jar]
+ [java] Module info 'META-INF/test.kotlin_module' exists
+
+BUILD SUCCESSFUL
+Total time: [time]
+
+Return code: 0
diff --git a/compiler/testData/integration/ant/jvm/moduleName/build.xml b/compiler/testData/integration/ant/jvm/moduleName/build.xml
new file mode 100644
index 00000000000..4f4738428d1
--- /dev/null
+++ b/compiler/testData/integration/ant/jvm/moduleName/build.xml
@@ -0,0 +1,14 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/compiler/testData/integration/ant/jvm/moduleName/hello.kt b/compiler/testData/integration/ant/jvm/moduleName/hello.kt
new file mode 100644
index 00000000000..dfc8315b01c
--- /dev/null
+++ b/compiler/testData/integration/ant/jvm/moduleName/hello.kt
@@ -0,0 +1,11 @@
+package hello
+
+fun main(args : Array) {
+ val systemClassLoader = ClassLoader.getSystemClassLoader()
+ val moduleName = "META-INF/test.kotlin_module"
+ val resourceAsStream = systemClassLoader.getResourceAsStream(moduleName)
+
+ if (resourceAsStream != null) {
+ println("Module info '$moduleName' exists")
+ }
+}
diff --git a/compiler/testData/integration/ant/jvm/moduleNameDefault/build.log.expected b/compiler/testData/integration/ant/jvm/moduleNameDefault/build.log.expected
new file mode 100644
index 00000000000..ead2cbe8b0d
--- /dev/null
+++ b/compiler/testData/integration/ant/jvm/moduleNameDefault/build.log.expected
@@ -0,0 +1,11 @@
+OUT:
+Buildfile: [TestData]/build.xml
+
+build:
+ [kotlinc] Compiling [[TestData]/hello.kt] => [[Temp]/hello.jar]
+ [java] Module info 'META-INF/build.kotlin_module' exists
+
+BUILD SUCCESSFUL
+Total time: [time]
+
+Return code: 0
diff --git a/compiler/testData/integration/ant/jvm/moduleNameDefault/build.xml b/compiler/testData/integration/ant/jvm/moduleNameDefault/build.xml
new file mode 100644
index 00000000000..23fc47d8f15
--- /dev/null
+++ b/compiler/testData/integration/ant/jvm/moduleNameDefault/build.xml
@@ -0,0 +1,14 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/compiler/testData/integration/ant/jvm/moduleNameDefault/hello.kt b/compiler/testData/integration/ant/jvm/moduleNameDefault/hello.kt
new file mode 100644
index 00000000000..a161a0b029c
--- /dev/null
+++ b/compiler/testData/integration/ant/jvm/moduleNameDefault/hello.kt
@@ -0,0 +1,11 @@
+package hello
+
+fun main(args : Array) {
+ val systemClassLoader = ClassLoader.getSystemClassLoader()
+ val moduleName = "META-INF/build.kotlin_module"
+ val resourceAsStream = systemClassLoader.getResourceAsStream(moduleName)
+
+ if (resourceAsStream != null) {
+ println("Module info '$moduleName' exists")
+ }
+}
diff --git a/compiler/tests/org/jetbrains/kotlin/integration/AntTaskTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/integration/AntTaskTestGenerated.java
index 767b993702c..1db5817d4f2 100644
--- a/compiler/tests/org/jetbrains/kotlin/integration/AntTaskTestGenerated.java
+++ b/compiler/tests/org/jetbrains/kotlin/integration/AntTaskTestGenerated.java
@@ -65,6 +65,18 @@ public class AntTaskTestGenerated extends AbstractAntTaskTest {
doTest(fileName);
}
+ @TestMetadata("moduleName")
+ public void testModuleName() throws Exception {
+ String fileName = JetTestUtils.navigationMetadata("compiler/testData/integration/ant/jvm/moduleName/");
+ doTest(fileName);
+ }
+
+ @TestMetadata("moduleNameDefault")
+ public void testModuleNameDefault() throws Exception {
+ String fileName = JetTestUtils.navigationMetadata("compiler/testData/integration/ant/jvm/moduleNameDefault/");
+ doTest(fileName);
+ }
+
@TestMetadata("noStdlibForJavac")
public void testNoStdlibForJavac() throws Exception {
String fileName = JetTestUtils.navigationMetadata("compiler/testData/integration/ant/jvm/noStdlibForJavac/");