Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

maven-source-plugin not work for kotlin

I am trying to use maven-source-plugin to create a source.jar for my kotlin project, but seems the maven-source-plugin not work well for kotlin project.

when i run "mvn source:jar", the output message always says:

[INFO] No sources in project. Archive not created.

here is the maven-source-plugin configuration in my pom file of the project:

    <build>
    <plugins>

        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-source-plugin</artifactId>
            <version>2.2.1</version>
            <executions>
                <execution>
                    <id>attach-sources</id>
                    <phase>package</phase>
                    <goals>
                        <goal>jar</goal>
                    </goals>
                    <configuration>
                        <attach>true</attach>
                        <includes>
         <!-- i am trying to specify the include dir manually, but not work -->                               
                         <include>${project.basedir}/src/main/kotlin/*</include>
                        </includes>
                        <forceCreation>true</forceCreation>
                    </configuration>
                </execution>
            </executions>
        </plugin>
    </plugins>
</build>

my question is: how to attach kotlin source files using maven-source-plugin?

thanks ~~

like image 693
Ace.Yin Avatar asked Nov 23 '16 12:11

Ace.Yin


People also ask

Can you use maven with kotlin?

The kotlin-maven-plugin compiles Kotlin sources and modules. Currently, only Maven v3 is supported.

How do I add a maven project to kotlin?

Add Kotlin Maven Plugin Now we need to tune this pom file so that it can handle Kotlin sources as well. Then, we need to add the kotlin-maven-plugin to our Maven plugins. We'll configure it to handle both compile and test-compile goals, telling it where to find our sources. This is nearly the end of the configuration.

What is maven source plugin?

The source plugin creates a JAR file with the project source code. It defines five goals: aggregate, jar, test-jar, jar-no-fork, and test-jar-no-fork. All these five goals of the source plugin will run under the package phase of the default lifecycle.


1 Answers

When your project has mixed Java and Kotlin (i.e. multiple source roots), I found that using the build-helper-maven-plugin worked well to ensure that both Java and Kotlin sources are included in the built sources artifact.

<plugin>
  <groupId>org.codehaus.mojo</groupId>
  <artifactId>build-helper-maven-plugin</artifactId>
  <version>3.0.0</version>

  <executions>
    <execution>
      <phase>generate-sources</phase>
      <goals>
        <goal>add-source</goal>
      </goals>
      <configuration>
        <sources>
          <source>src/main/kotlin</source>
        </sources>
      </configuration>
    </execution>
  </executions>
</plugin>
like image 123
Alex Avatar answered Sep 17 '22 14:09

Alex