Closed yadavan88 closed 1 month ago
Managed to get it working with the following setup:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.example</groupId>
<artifactId>maven-scala-seed3</artifactId>
<version>1.0-SNAPSHOT</version>
<name>maven-scala-seed3</name>
<description>A minimal Scala project using the Maven build tool.</description>
<licenses>
<license>
<name>My License</name>
<url>http://....</url>
<distribution>repo</distribution>
</license>
</licenses>
<properties>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<encoding>UTF-8</encoding>
<scala.version>3.3.3</scala.version>
</properties>
<dependencies>
<dependency>
<groupId>org.scala-lang</groupId>
<artifactId>scala3-library_3</artifactId>
<version>${scala.version}</version>
</dependency>
<dependency>
<groupId>org.scala-lang</groupId>
<artifactId>scala3-compiler_3</artifactId>
<version>${scala.version}</version>
</dependency>
<!-- Test -->
<dependency>
<groupId>org.scalameta</groupId>
<artifactId>munit_3</artifactId>
<version>1.0.0</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<sourceDirectory>src/main/scala</sourceDirectory>
<testSourceDirectory>src/test/scala</testSourceDirectory>
<plugins>
<plugin>
<!-- see http://davidb.github.com/scala-maven-plugin -->
<groupId>net.alchim31.maven</groupId>
<artifactId>scala-maven-plugin</artifactId>
<version>4.9.2</version>
<configuration></configuration>
<executions>
<execution>
<goals>
<goal>compile</goal>
<goal>testCompile</goal>
</goals>
<configuration>
<args></args>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
// ./src/main/scala/Smth.scala
@main def main = println("Hello from Maven")
works fine with
mvn scala:run -DmainClass=main
Thanks @Gedochao It was my mistake. I was trying with -DmainClass=SampleMaven
instead of -DmainClass=main
It works now.
I will close this issue now.
Hi, I am trying to implement scala-cli export option to Maven. However, I am facing an issue. Here is the Scala code (in
src/main/scala
directory):Here is my pom.xml:
When I execute the goal
mvn compile exec:java -Dexec.mainClass=SampleMaven
it fails to execute. If I change the scala code to:It works.
One more thing, when I run it using
mvn compile exec:java -Dexec.mainClass=SampleMaven
sometimes it fails. but if I domvn clean
first thenmvn compile
and then execute theexec:java
command, it passes.I haven't worked with Maven for over 7 years now, so I am not sure what is wrong. It seems the main class is not discoverable with the new
@main
annotation usage.Edit: Forgot to mention: I also tried with
mvn scala:run -DmainClass=SampleMaven
but got the same error about main not foundThanks in advance