[SOLVED] Maven: Set target/output directory

Answered

Hello. I want to set the target/output directory for my maven build. I searched on the internet for over an hour, but I can't find anything that works. The closed I got, was with <outputDirectory>Z:/dev-network/server1/plugins</outputDirectory> in <build>, but that exports the classes as folders, I want the jar in that directory, which is now still in the target directory in my project.

Aside from that, it also doesn't package other files (like my plugin.yml) or the dependencies. Here is my pom.xml.

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>xyz.prismacraft.prismacore</groupId>
<artifactId>PrismaCore</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>11</source>
<target>11</target>
</configuration>
</plugin>
</plugins>
</build>

<repositories>
<repository>
<id>spigot-repo</id>
<url>https://hub.spigotmc.org/nexus/content/repositories/public/</url>
</repository>
</repositories>

<dependencies>
<dependency>
<groupId>org.spigotmc</groupId>
<artifactId>spigot-api</artifactId>
<version>1.16.5-R0.1-SNAPSHOT</version><!--change this value depending on the version or use LATEST-->
<type>jar</type>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.squareup.okhttp3</groupId>
<artifactId>okhttp</artifactId>
<version>3.14.2</version>
</dependency>
</dependencies>

</project>

I know I got the dependencies right, because the smart autocomplete from IntelliJ does work correctly.

And something else, from the maven options, should I use compilepackage or both of them and what is the difference? I'm very new to marven and IntelliJ, I'm sorry for these stupid questions :-(

0
4 comments

To specify the output directory for the jar artifact, configure it for the maven-jar-plugin which builds the jar artifact:

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.3.1</version>
<configuration>
<outputDirectory>my-target-dir</outputDirectory>
</configuration>
</plugin>

>Aside from that, it also doesn't package other files (like my plugin.yml) or the dependencies. 

Make sure you placed them into the resources directory.

0

Hello. Thank you for your response, it worked! Now I'm just left with the dependency problem. In my plugin, I want to use okhttp. But when I package my build, it doesn't contain the okhttp code. I used Alt+Insert to find the package, this is my dependencies list. What can I do to fix that?

<dependencies>
<dependency>
<groupId>org.spigotmc</groupId>
<artifactId>spigot-api</artifactId>
<version>1.16.5-R0.1-SNAPSHOT</version><!--change this value depending on the version or use LATEST-->
<type>jar</type>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.squareup.okhttp3</groupId>
<artifactId>okhttp</artifactId>
<version>3.14.2</version>
</dependency>
</dependencies>
0

It works now. Thank you so much for all your help, and again sorry for these stupid questions, I'm just not familiar with maven.

0

Please sign in to leave a comment.