Generate and run Maven Kotlin jar - maven

I'm trying to generate a jar file of my kotlin project.
I read Maven Kotlin and copied the code into my pom.xml but I don't understand what I'm supposed to insert at ${main.class}.
Here is my code architecture with MorisKt.java as my main class.
I tried MorisKt.class, /MorisKt.class, target/Moris.class(container folder of my compiled code)
And nothing worked. The jar is generated but I have Could not find or load main class when I try to run it.
If you can explain me where I'm doing it wrong

You need to put your main class file in a package and then reference it with the fully qualified name.
For instance if you put your Moris.kt in a package named app it would be :
<mainClass>app.MorisKt</mainClass>

Related

Gradle test library in multi module project

I want to create a library that other modules in my project can depend on, but only for tests. I've read the Gradle documentation extensively and couldn't find how to do it. This is my project structure:
gradle-example:
app:
src/main/kotlin ...
src/test/kotlin <- this is supposed to use 'com.example.SomeTestUtil'
testlib:
src/test/kotlin/com.example.SomeTestUtil
settings.gradle.kts:
rootProject.name = "gradle-example"
include("app")
include("testlib")
In the app module I tried adding
dependencies {
testImplementation(project(:testlib"))
}
But I get compilation error trying to import the SomeTestUtil in the app module test classes.
What is the correct way to declare dependency on a module in the same project that allows to use test sources in test code?
To clarify, we want to create a library that can only be used by other modules under src/test and not src/main.
Apparently this can be done by using the https://docs.gradle.org/current/userguide/java_testing.html#sec:java_test_fixtures
they can see the main source set classes
test sources can see the test fixtures classes
So changes to the example in the question are:
changing the src/test to src/testFixtures
declaring the dependency as testImplementation(testFixtures(project(":testlib")))
Adding java-test-fixtures plugin to the build.gradle.kts for the testlib module

How can build.gradle be configured to check for classes from src\main\java instead of src\test\java?

I have a gradle project (converted from an original ANT project). The directory structure is as advised by gradle so my source is in src\main\java and test is in src\test\java.
However, because the package structure of src\test is almost exactly similar to src\main, during the test run phase in gradle, I get a bunch of
java.lang.NoClassDefFoundError
even though I can clearly see the code under ,say, src\main\A.B.C\Y\X.java. I am suspecting that while running the tests, the class to import is being searched under src\test\A.B.C\Y where, of course, the class X is not present

How to properly use a referenceJar in Xamarin Android Project?

I have a .aar file that contains a SDK, it needs the gson library to work, so i added the gson.jar file into the project as a ReferenceJar, but it cannot find the reference.
I've already tried to extract the jar from the aar, and use one as InputJar and the gson jar as ReferenceJar, it did not work.
In this case the java code spits this error:
java.lang.NoClassDefFoundError: Failed resolution of: Lcom/google/gson/Gson;
I've tried to create a separate project that contains only the gson file as a InputJar and use it as a dependency on the other project.
In this case the gson project does not compile, VS spits errors like
CS0534 "CollectionTypeAdapterFactory.Adapter" does not implement inherited abstract member "TypeAdapter.Read(JsonReader)"
I've also tried to add the gson.jar file into the libs folder inside the .aar file, but gave me the same compiling errors as described above
So, what should I do next?
I figured out.
I had to extract the jar from the .aar and set it as an EmbeddedJar and the gson library as EmbeddedReferenceJar. Somehow it worked. If someone could explain me why, it would be nice.

Import java class to Jsp in Maven project

I have a project in IDE, so I made a new project in Maven. I copy all the files and classes, and I fill the pom.xml.
This is OK, but the problem is in JSP,eclipse dont find the imported clases.
<%#page import="modelos.Mascota"%>
This import for example cant be resolved.
What I'm doing wrong?
All my java classes are in:
\src\main\resources
And jsp files in:
src\main\webapp
Your .java files must be in
\src\main\java
check your dependencies for the class whether it is exist or not
modelos.Mascota

Setting dependency of a component to mantle-usl - custom Groovy class

I have a custom groovy class inside mantle-usl component. I would like to use the class in other component. Hence, I need to add a dependency so that the new component (or project) has the jar of mantle-usl ready for use.
Is there anyone who can help with this? I attempted to modify the build.gradle file of the project. And add a project dependency, but it returned an error.
project(':runtime/component/warehouse-items-masterenumerator') {
dependencies {
compile project(':runtime/component/mantle-usl')
}
}
As you would expect, this does not work. It seems that I do not have the project references set correctly.
The mantle-usl component doesn't have any compiled code in it so the build.gradle file does not build a jar file, it is only used for running the Spock tests.
I wouldn't recommend adding your own code to mantle-usl, it is easier and cleaner to put it in a separate component. For an example of a build.gradle file that does build a jar file look at the moqui/example component or most of the moqui tool components (such as moqui-elasticsearch).
You also don't need to modify the main build.gradle file from the moqui-framework repository, dependencies should be declared in the build.gradle file in each component (which are picked up automatically in the main build).

Resources