Creating apklibs with maven and IntelliJ - java

I'm creating a apklib from sliding menu because I couldn't find any maven repository. The problem is that when I try from intellij, It imports the library but doesn't add the dependencies to sliding menu library and I have to add it manually.
<?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/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.slidingmenu</groupId>
<artifactId>library</artifactId>
<version>1.2</version>
<type>apklib</type>
<dependencies>
<dependency>
<groupId>com.google.android</groupId>
<artifactId>android</artifactId>
<version>4.1.1.4</version>
</dependency>
<dependency>
<groupId>com.google.android.maps</groupId>
<artifactId>maps</artifactId>
</dependency>
<dependency>
<groupId>com.google.android</groupId>
<artifactId>support-v13</artifactId>
<version>r12</version>
</dependency>
<dependency>
<groupId>com.github.rtyley</groupId>
<artifactId>roboguice-sherlock</artifactId>
<version>1.5</version>
</dependency>
<dependency>
<groupId>org.roboguice</groupId>
<artifactId>roboguice</artifactId>
<version>2.0</version>
</dependency>
<dependency>
<groupId>com.actionbarsherlock</groupId>
<artifactId>actionbarsherlock</artifactId>
<version>4.2.0</version>
<type>apklib</type>
</dependency>
</dependencies>
<build>
<sourceDirectory>src</sourceDirectory>
<plugins>
<plugin>
<groupId>com.jayway.maven.plugins.android.generation2</groupId>
<artifactId>android-maven-plugin</artifactId>
<extensions>true</extensions>
<configuration>
<nativeLibrariesDirectory>ignored</nativeLibrariesDirectory>
</configuration>
</plugin>
</plugins>
</build>
</project>
I create the zip, according to the instructions on maven plugin and then I push it to ~/.m2 with this command:
mvn org.apache.maven.plugins:maven-install-plugin:2.4:install-file -DgroupId=com.slidingmenu -DartifactId=library -Dfile=sliding-menu.apklib -Dversion=1.2 -Dpackaging=apklib

You need to install com.slidingmenu in your local repository with mvn clean install instead of install:install-file
mvn clean install will put all the meta-data and the dependencies required by maven in your local repository (i.e. ~/.m2/repository).
In your apk, specify the artifact com.slidingmenu as a dependency of type apklib
I hope it will solve your problems.

Related

maven dependency not properly compile into war

I am using the Eclipse IDE and in the past, I have been developing a maven project depending on local sources (from github (sap-olingo)) as well as maven dependencies loaded as jar. I have now updated the github source and also all the dependencies which seems to break standard eclipse export functionalities (right click porject -> export -> war)
The webproject is working fine when using the maven install functionality and is loading all sources into the META-INF/lib classes, but when using the export as war from eclipse (which I did previously) it is missing to compile a proper dependency. Missing in the sense of that the jar is still present in the META-INF/lib directory of the war, but the content is empty and the size is only 1kb
When comparing the mvn clean install to the exported, there are rarely any differences. Except for the projects that are to be compiled during the runtime. Sizes of the libs in the mvn created war and the exported war roughly matches except for that one jar.
Is there a way to root cause that issue? I am using solely the maven integrated into the IDE which is why I doubt differences in the maven versions and or jdk.
Unfortunately I have no idea in where to start and what info you require
Thanks for your input
EDIT:
My projects pom:
<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/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.test</groupId>
<artifactId>odata</artifactId>
<packaging>war</packaging>
<version>4.0.0</version>
<name>odataMaven Webapp</name>
<url></url>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.sap.olingo</groupId>
<artifactId>odata-jpa-processor</artifactId>
<version>0.3.7-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>com.microsoft.sqlserver</groupId>
<artifactId>mssql-jdbc</artifactId>
<version>6.1.0.jre8</version>
</dependency>
<dependency>
<groupId>org.eclipse.persistence</groupId>
<artifactId>javax.persistence</artifactId>
<version>2.1.0</version>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
<version>2.5</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.eclipse.persistence</groupId>
<artifactId>eclipselink</artifactId>
<version>2.6.2</version>
</dependency>
</dependencies>
<build>
<finalName>odata</finalName>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.17</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>${project.build.source}</source>
<target>${project.build.source}</target>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.build.source>1.8</project.build.source>
</properties>
</project>
The odata-jpa-processor source/project is pulled from here. The problem exists solely with the olingo-jpa-metadata jar which is empty. All other maven dependencies are exported correctly.

maven property is not overrided with -dParam.version

When i exeute:
mvn -Dparam.version=9 help:effective-pom | clip
in the command line on Windows 10 i get all over this clip only:
<properties>
<param.version>4</param.version>
</properties>
which is the old version.
How can i force to change this param?
In the cmd:
mvn --version
Apache Maven 3.5.4
Froms poms:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.3</version>
<configuration>
<source>${java.version}</source>
<target>${java.version}</target>
</configuration>
</plugin>
EDIT:
I use this property to set depedency version for example:
<dependency>
<groupId>x</groupId>
<artifactId>c-api/artifactId>
<version>${param.version}</version>
</dependency>
inside c-api we can see:
<?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>
<parent>
<groupId>x</groupId>
<artifactId>c</artifactId>
<version>4</version>
</parent>
<artifactId>c-api</artifactId>
<packaging>jar</packaging>
<dependencies>
<dependency>
<groupId>x</groupId>
<artifactId>c-api</artifactId>
</dependency>
<dependency>
<groupId>x</groupId>
<artifactId>p-api</artifactId>
</dependency>
<dependency>
<groupId>x</groupId>
<artifactId>f-api</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-commons</artifactId>
</dependency>
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
</project>
First, you need use -Dparam.version instead -dParam.version.
If
<properties>
<param.version>4</param.version>
</properties
is defined in the xxx.pom file, you are not allowed to change it using command line, while you are free to override it. And in this case, though the value is still 4 in the pom file, others which refer it by ${param.version} will pick 9.
You are looking in the incorrect place when checking if your command line parameter has been correctly applied.
If you entered the command mvn -Dparam.version=9 help:effective-pom then you should see your dependency version evaluated correctly.
Where your pom has
...
<dependency>
<groupId>x</groupId>
<artifactId>c-api</artifactId>
<version>${param.version}</version>
</dependency>
...
the output of the command will display
...
<dependency>
<groupId>x</groupId>
<artifactId>c-api</artifactId>
<version>9</version>
</dependency>
...
If you just run mvn help:effective-pom you will see
...
<dependency>
<groupId>x</groupId>
<artifactId>c-api</artifactId>
<version>4</version>
</dependency>
...
with the version specified in the pom properties displayed instead.

How can I generate a maven repository-ready library with swagger-codegen-maven-plugin?

I'm using the Maven plugin swagger-codegen-maven-plugin to generate a Java client jar. I put my swagger.json in the src/main/resources folder and ran mvn clean install. Here is my pom.xml.
<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/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.example</groupId>
<artifactId>my-java-client</artifactId>
<packaging>jar</packaging>
<version>1.0-SNAPSHOT</version>
<name>my-java-client</name>
<url>http://maven.apache.org</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
<swagger.version>1.5.13</swagger.version>
</properties>
<dependencies>
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.8.0</version>
</dependency>
<dependency>
<groupId>com.squareup.okhttp</groupId>
<artifactId>okhttp</artifactId>
<version>2.7.5</version>
</dependency>
<dependency>
<groupId>com.squareup.okhttp</groupId>
<artifactId>logging-interceptor</artifactId>
<version>2.7.5</version>
</dependency>
<dependency>
<groupId>io.swagger</groupId>
<artifactId>swagger-codegen</artifactId>
<version>2.2.2</version>
</dependency>
<dependency>
<groupId>com.squareup.okio</groupId>
<artifactId>okio</artifactId>
<version>1.12.0</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>io.swagger</groupId>
<artifactId>swagger-codegen-maven-plugin</artifactId>
<version>2.2.2</version>
<executions>
<execution>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<inputSpec>src/main/resources/swagger.json</inputSpec>
<modelPackage>mypackage.model</modelPackage>
<apiPackage>mypackage</apiPackage>
<invokerPackage>mypackage.invoker</invokerPackage>
<language>java</language>
<configOptions>
<interfaceOnly>true</interfaceOnly>
<dateLibrary>java8</dateLibrary>
<java8>true</java8>
</configOptions>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
When I run mvn clean install, a jar file my-java-client-1.0-SNAPSHOT.jar is made in the target folder. It has source code in it, but no pom.xml file. There is a pom.xml file in the target/generated-sources/swagger folder but it has the groupId and artifactId:
<groupId>io.swagger</groupId>
<artifactId>swagger-java-client</artifactId>
The README.md file in the target/generated-sources/swaggersays to include the following in your pom.xml to use the generated jar:
<dependency>
<groupId>io.swagger</groupId>
<artifactId>swagger-java-client</artifactId>
<version>1.0.0</version>
<scope>compile</scope>
</dependency>
I'm guessing these are just defaults because if I generated multiple swagger clients they would conflict over the name, and I can see in the swagger-codegen source code that these fields are generated from placeholders like {{artifactId}}. I haven't been able to find where I can set these placeholders.
How can I get the jar to include a pom.xml with an artifactId and groupId of my choosing, so I can upload it to a Maven repository like Artifactory, and use it in my Maven dependencies?
It's not particularly well documented, but it appears you are able to override the artifactId, groupId etc from within the configOptions:
<configOptions>
<groupId>com.your.group.id</groupId>
<artifactId>your-artifact-id</artifactId>
<artifactVersion>0.0.1-SNAPSHOT</artifactVersion>
</configOptions>
Many of the properties inside CodegenConstants.java can be set in the same way.
I updated it using below config Properties (gradle)
'groupId' : 'your.group.id',
'artifactId' : 'your-artifact-id'
you can also go through document which is helpful for reference of the properties.
https://openapi-generator.tech/docs/generators/kotlin/

org.codehaus.plexus.component.repository.exception.ComponentLookupException: java.util.NoSuchElementException

I try to test my maven plugin and receive weird exception. Found similar question here, but the answer didn't help.
pom.xml
<dependencies>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-plugin-api</artifactId>
<version>3.3.9</version>
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-project</artifactId>
<version>3.0-alpha-2</version>
</dependency>
<dependency>
<groupId>com.jcabi</groupId>
<artifactId>jcabi-aether</artifactId>
<version>0.10.1</version>
</dependency>
<dependency>
<groupId>org.apache.maven.plugin-tools</groupId>
<artifactId>maven-plugin-annotations</artifactId>
<version>3.4</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.maven.plugin-testing</groupId>
<artifactId>maven-plugin-testing-harness</artifactId>
<version>3.3.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-aether-provider</artifactId>
<version>3.3.9</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-core</artifactId>
<version>3.3.9</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-compat</artifactId>
<version>3.3.9</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-model</artifactId>
<version>3.3.9</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
</dependencies>
Test class:
public class ConverterMojoTest {
#Rule
public MojoRule rule = new MojoRule() {
#Override
protected void before() throws Throwable {
super.before();
}
#Override
protected void after() {
super.after();
}
};
#Rule
public TestResources resources = new TestResources();
#Test
public void testExecute() throws Exception {
File project = resources.getBasedir("valid");
File pom = new File(project, "pom.xml");
Assert.assertNotNull(pom);
Assert.assertTrue(pom.exists());
ConverterMojo mojo = (ConverterMojo) rule.lookupMojo("convert", pom);
Assert.assertNotNull(mojo);
mojo.execute();
}
}
Test project pom.xml:
<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>com.my.utils.test</groupId>
<artifactId>project-to-test</artifactId>
<version>1.0.0-SNAPSHOT</version>
<packaging>jar</packaging>
<name>Test</name>
<build>
<plugins>
<plugin>
<groupId>com.my.utils</groupId>
<artifactId>converter-maven-plugin</artifactId>
<configuration>
</configuration>
</plugin>
</plugins>
</build>
</project>
Exception:
org.codehaus.plexus.component.repository.exception.ComponentLookupException: java.util.NoSuchElementException
role: org.apache.maven.plugin.Mojo
roleHint: com.my.utils:converter-maven-plugin:1.0.0-SNAPSHOT:convert
I was facing this issue in one of the modules that had proper execution configuration with the appropriate goal. I resolved this by simply running mvn clean install in that specific module (without deleting anything from the local repo).
Your test project's pom.xml needs to have the an <execution/> section with the respective <goal/>:
<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>com.my.utils.test</groupId>
<artifactId>project-to-test</artifactId>
<version>1.0.0-SNAPSHOT</version>
<packaging>jar</packaging>
<name>Test</name>
<build>
<plugins>
<plugin>
<groupId>com.my.utils</groupId>
<artifactId>converter-maven-plugin</artifactId>
<configuration>
...
</configuration>
<executions>
<execution>
<goals>
<goal>convert</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
Otherwise, the testing harness will fail to understand what it has to map and load.
Just update the maven project and mvn clean install. It will work
I had the same issue, followed all of the advice but still had the issue. I solved it by clearing out my local repo then doing a mvn clean install -DskipTests from terminal. Then I ran my jUnit test from Eclipse and it worked. Must have been a conflicting dependency somewhere.
open your location
File | Settings | Build, Execution, Deployment | Build Tools | Maven
Change "maven home path:" to Use Maven wrapper here. This is how my problem was solved.enter image description here

How to disable karaf-maven-plugin 4 tight dependency constraint checks

Currently I am moving from karaf 3.0.5 to the newest version 4.0.2, I do assembly my own karaf with the karaf-maven-plugin. This is how my pom looks like.
<?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">
<parent>
<groupId>my.own.group</groupId>
<artifactId>assemble</artifactId>
<version>1.14.0-SNAPSHOT</version>
<relativePath>..</relativePath>
</parent>
<artifactId>karaf-customize</artifactId>
<modelVersion>4.0.0</modelVersion>
<packaging>karaf-assembly</packaging>
<dependencies>
<dependency>
<groupId>org.apache.karaf.features</groupId>
<artifactId>framework</artifactId>
<version>${karaf.version}</version>
<type>kar</type>
</dependency>
<dependency>
<groupId>org.apache.karaf.features</groupId>
<artifactId>standard</artifactId>
<classifier>features</classifier>
<version>${karaf.version}</version>
<type>xml</type>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.apache.cxf.karaf</groupId>
<artifactId>apache-cxf</artifactId>
<classifier>features</classifier>
<version>${cxf.version}</version>
<type>xml</type>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.apache.karaf.features</groupId>
<artifactId>enterprise</artifactId>
<classifier>features</classifier>
<version>${karaf.version}</version>
<type>xml</type>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>my.own.group</groupId>
<artifactId>kar-archive</artifactId>
<version>1.14.0-SNAPSHOT</version>
<type>pom</type>
<optional>true</optional>
</dependency>
<dependency>
<groupId>my.own.group</groupId>
<artifactId>karaf-branding</artifactId>
<version>1.14.0-SNAPSHOT</version>
<optional>true</optional>
</dependency>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.4</version>
</dependency>
<dependency>
<groupId>com.alutam</groupId>
<artifactId>ziputils</artifactId>
<version>1.1</version>
</dependency>
<dependency>
<groupId>wsdl4j</groupId>
<artifactId>wsdl4j</artifactId>
<version>1.6.3</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.karaf.tooling</groupId>
<artifactId>karaf-maven-plugin</artifactId>
<version>${karaf.version}</version>
<extensions>true</extensions>
<configuration>
<javase>1.8</javase>
<bootFeatures>
<feature>jasypt-encryption</feature>
<feature>config</feature>
<feature>standard</feature>
<feature>region</feature>
<feature>management</feature>
<feature>bundle</feature>
<feature>package</feature>
<feature>kar</feature>
<feature>ssh</feature>
<feature>http</feature>
<feature>cxf</feature>
<feature>service-wrapper</feature>
<feature>jdbc</feature>
<feature>system</feature>
</bootFeatures>
</configuration>
</plugin>
</plugins>
</build>
</project>
With this configuration I do get the following error for several dependencies.
Caused by: org.osgi.framework.BundleException: Unsupported 'Bundle-ManifestVersion' value: 1
at org.apache.karaf.features.internal.resolver.ResourceBuilder.doBuild(ResourceBuilder.java:88)
at org.apache.karaf.features.internal.resolver.ResourceBuilder.build(ResourceBuilder.java:78)
I guess it happens within this parser. The reason is some old third party libraries have only Bundle-ManifestVersion: 1 set within their manifest file.
With karaf-maven-plugin 3.x this didn't matter at all. In contrast the karaf-maven-plugin 4.x fails with message above.
The only way I know to fix this is either rebuild from source or repack the hole jar again.
Is there any other way like a configuration for the karaf-maven-plugin to disable this constraint check? Because it would be awful lot of work to get all of this bundles up an running, again.
I faced the same error when updating to Karaf 4 and you have two choices:
Osgify conflictive dependency using bndtools:
Download bnd tools
Open a shell where you have downloaded bnd-2.4.0.jar.
Type:
java -jar bnd-2.4.0.jar wrap -o osgify-dependency.jar dependency.jar
where dependency.jar is your third party and osgify-dependency.jar will be the output.
Deploy to maven repo overriding the previous maven coordinates, or deploy your thirdparty with different coordinates.
mvn deploy:deploy-file -Dfile osgify-dependency.jar ..
Enable the wrap protocol
Add to you maven karaf plugin wrap and wrapper features.
So you can use wrap protocol to fix your corrupted MANIFEST.MF
Inside some karaf features:
<bundle>wrap:mvn:group.id/third.party.artefact.id/version</bundle>
Inside your pom.xml notice feature wrap / wrapper.
<plugin>
<groupId>org.apache.karaf.tooling</groupId>
<artifactId>karaf-maven-plugin</artifactId>
<extensions>true</extensions>
<executions>
</executions>
<configuration>
<!-- no startupFeatures -->
<bootFeatures>
<feature>feature</feature>
<feature>jaas</feature>
<feature>shell</feature>
<feature>ssh</feature>
<feature>management</feature>
<feature>bundle</feature>
<feature>config</feature>
<feature>deployer</feature>
<feature>diagnostic</feature>
<feature>instance</feature>
<feature>kar</feature>
<feature>log</feature>
<feature>package</feature>
<feature>service</feature>
<feature>system</feature>
<feature>wrap</feature>
<feature>aries-blueprint</feature>
</bootFeatures>
<installedFeatures>
..
<feature>wrapper</feature>
</installedFeatures>
</configuration>
</plugin>
Here you have the full code where i tested:
https://github.com/antoniomaria/gazpachoquest/blob/master/karaf-assembly/pom.xml

Categories

Resources