maven-source-plugin不适用于kotlin

Ace*_*Yin 8 maven-source-plugin kotlin

我正在尝试使用maven-source-plugin为我的kotlin项目创建一个source.jar,但似乎maven-source-plugin对kotlin项目效果不佳.

当我运行"mvn source:jar"时,输出消息总是说:

[INFO] No sources in project. Archive not created.
Run Code Online (Sandbox Code Playgroud)

这是我项目的pom文件中的maven-source-plugin配置:

    <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>
Run Code Online (Sandbox Code Playgroud)

我的问题是:如何使用maven-source-plugin附加kotlin源文件?

谢谢~~

Ale*_*lex 17

当你的项目混合了Java和Kotlin(即多个源根)时,我发现使用build-helper-maven-plugin工作得很好来确保Java和Kotlin源都包含在构建的源工件中.

<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>
Run Code Online (Sandbox Code Playgroud)


Ily*_*lya 9

默认情况下,maven期望源位于src/main/java目录中.如果使用非默认目录,则必须在build元素中指定它们:

<build>
    <sourceDirectory>src/main/kotlin</sourceDirectory>
    <testSourceDirectory>src/test/kotlin</testSourceDirectory>
</build>
Run Code Online (Sandbox Code Playgroud)

  • 不幸的是,如果您的项目同时具有Java和Kotlin源根,那么执行此操作将导致您的源工件仅包含Kotlin源. (2认同)