# Maven with generated Java sources?

**URL:** <https://discuss.kotlinlang.org/t/maven-with-generated-java-sources/17783>\
**Category:** Uncategorized\
**Created:** [May 21, 2020, 9:09pm UTC](https://discuss.kotlinlang.org/t/maven-with-generated-java-sources/17783 "2020-05-21T21:09:21Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![rnikander](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.kotlinlang.org/rnikander/32/6881_2.png) [@rnikander](https://discuss.kotlinlang.org/u/rnikander)\
**Post date:** [May 21, 2020, 9:09pm UTC](https://discuss.kotlinlang.org/t/maven-with-generated-java-sources/17783/1 "2020-05-21T21:09:22Z")

</div>

I’m trying to add Kotlin to an existing project with a big maven pom.xml file. I followed the instructions [here](https://kotlinlang.org/docs/reference/using-maven.html). The Maven build uses plugins like `maven-jaxb2-plugin` to generate Java sources. The problem is those Java classes are not available to the Kotlin code. Is there a recommendation for this situation? Should I just manually add the generated source directories to the configuration of the Kotlin plugin, like this?

```
<plugin>
   <groupId>org.jetbrains.kotlin</groupId>
   <artifactId>kotlin-maven-plugin</artifactId>
   ...
   <sourceDirs>
     <source>src/main/java</source>
     <source>src/main/kotlin</source>
     <source>target/generated-sources/foo</source>
     ...
   </sourceDirs>

```

---

<div class="post-metadata">

**Author:** ![jozuaherfst](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.kotlinlang.org/jozuaherfst/32/8490_2.png) [@jozuaherfst](https://discuss.kotlinlang.org/u/jozuaherfst)\
**Post date:** [April 9, 2021, 9:14am UTC](https://discuss.kotlinlang.org/t/maven-with-generated-java-sources/17783/2 "2021-04-09T09:14:32Z")

</div>

I solved this by adding the correct source dir location **(target/generated-sources/xjc**):

```
           <configuration>
                   <sourceDirs>
                       <source>src/main/kotlin</source>
                       <source>target/generated-sources/xjc</source>
                   </sourceDirs>
          </configuration>

```

---

<div class="post-metadata">

**Author:** ![dinomite](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.kotlinlang.org/dinomite/32/7532_2.png) [@dinomite](https://discuss.kotlinlang.org/u/dinomite)\
**Post date:** [May 7, 2021, 5:54pm UTC](https://discuss.kotlinlang.org/t/maven-with-generated-java-sources/17783/3 "2021-05-07T17:54:37Z")

</div>

There is a Kotlin compiler plugin ticket [https://youtrack.jetbrains.com/issue/KT-13995](https://youtrack.jetbrains.com/issue/KT-13995)
