Package-Level Annotations in Kotlin (package-info.java for JAXB)

Hi everyone,
does Kotlin support annotations on package-level? I’m struggling with the conversion of the following Java code into Kotlin. It’s a typical package-info.java that is used by JAXB.

@XmlSchema(
xmlns = {
@XmlNs(prefix = “”, namespaceURI = Constants.XML_NAMESPACE_SPRD_URL),
@XmlNs(prefix = Constants.XML_NAMESPACE_XLINK, namespaceURI = Constants.XML_NAMESPACE_XLINK_URL)
},
namespace = Constants.XML_NAMESPACE_SPRD_URL,
elementFormDefault = XmlNsForm.QUALIFIED)
package net.sprd.exos.api.model;

import my.package.Constants;

import javax.xml.bind.annotation.XmlNs;
import javax.xml.bind.annotation.XmlNsForm;
import javax.xml.bind.annotation.XmlSchema;

Looking forward to your response!
Cheers Philipp

1 Like

No, it doesn’t. You can simply leave package-info.java as a Java file in your project.

Note that if package-info.java references classes in the same project (e.g. adapters):

Those classes also need to be in java, or they will not be visible when building package-info
And yes, build order needs to be java before kotlin, or your kotlin build will not be aware of the annotations in package-info.

IntelliJ may mask the problem, but it will appear when compiling with a build tool.