scala-maven-plugin unable to find source directory when mentioned in <configuration>

662 views Asked by At

When I compile Scala sources this pom.xml works :

<build>
    <sourceDirectory>${project.basedir}/src/main/scala</sourceDirectory>

    <plugins>
        <plugin>
            <groupId>net.alchim31.maven</groupId>
            <artifactId>scala-maven-plugin</artifactId>
            <version>4.4.0</version>
            
            <executions>
                <execution>
                    <id>scala-compile-first</id>
                    <phase>process-resources</phase>
                    <goals>
                        <goal>compile</goal>
                    </goals>
                </execution>
    [...]           

But not this alternative :

<build>
    <plugins>
        <plugin>
            <groupId>net.alchim31.maven</groupId>
            <artifactId>scala-maven-plugin</artifactId>
            <version>4.4.0</version>
            
            <executions>
                <execution>
                    <id>scala-compile-first</id>
                    <phase>process-resources</phase>
                    <goals>
                        <goal>compile</goal>
                    </goals>
                    
                    <configuration>
                        <sourceDir>${project.basedir}/src/main/scala</sourceDir>
                        <testSourceDir>${project.basedir}/src/test/scala</testSourceDir>
                    </configuration>
                </execution>
           [...]                

Even if sourceDir and testSourceDir are mentioned in the plugin documentation for this usage.

I need the second alternative because I this execution is followed by a call to the Java compiler that relies on other source file directory.

I tried a call to the add-source goal too. Without success.

1

There are 1 answers

0
David Bernard On

You tried to override de configuration with something wrong, I guess ${project.basedir} is not replaced by the expected value.

What you want is the default behavior, so you can simply remove the override

<build>
    <plugins>
        <plugin>
            <groupId>net.alchim31.maven</groupId>
            <artifactId>scala-maven-plugin</artifactId>
            <version>4.4.0</version>
            
            <executions>
                <execution>
                    <id>scala-compile-first</id>
                    <phase>process-resources</phase>
                    <goals>
                        <goal>compile</goal>
                    </goals>
                </execution>

Update: Check the log (output) to see which folder the plugin scan for compilation.