I personally prefer to keep my coding problem off of here unless I think I'm stumped. I'm trying to add the mysql java dependency to my project (I'm coding a Minecraft-Spigot 1.12.2 plugin).
I've been coding MySQL for years but I've never had to use it with Java until now so I'm following this tutorial: https://www.spigotmc.org/wiki/connecting-to-databases-mysql/
Which redirected me to this page: https://mvnrepository.com/artifact/mysql/mysql-connector-java/8.0.26
Naturally adding a Maven dep is easy enough you just copy and paste it! Beyond that, I'm not very in tune with the inner workings of the system.
Whenever I compile (it does in-fact compile without throwing any fits) and upload it to my servers I get this error: java.lang.NoClassDefFoundError: com/mysql/cj/jdbc/MysqlDataSource. Now, I know that this has to do with the class being undefined or something. So obviously, I searched the error code. A lot of the problems I saw didn't seem to apply to me.
I double checked and I DO see mysql-connector-java inside of my "External Libraries" section in my IDE (InteliJ IDEA)
I also saw some people sending this link: How can I create an executable JAR with dependencies using Maven?
Which, the answer didn't seem to help me out either (unless I missed something).
My hope is that by sending my file someone can help me out here?
I've seen some people mention that it could be a problem with a classpath? How exactly can I go about fixing that (if it is the problem). I couldn't seem to find anything to help me with that problem (tho in this case classpath is a little over my head. Def want to read up on it more in the future).
Here's my pom.xml any helpful assistance is appreciated!
<?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>com.example</groupId>
<artifactId>example</artifactId>
<version>1.12.2-SNAPSHOT</version>
<packaging>jar</packaging>
<name>example</name>
<properties>
<java.version>1.8</java.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<source>8</source>
<target>8</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.2.4</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<createDependencyReducedPom>false</createDependencyReducedPom>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
</resource>
</resources>
</build>
<repositories>
<repository>
<id>spigotmc-repo</id>
<url>https://hub.spigotmc.org/nexus/content/repositories/snapshots/</url>
</repository>
<repository>
<id>sonatype</id>
<url>https://oss.sonatype.org/content/groups/public/</url>
</repository>
<repository>
<id>dmulloy2-repo</id>
<url>https://repo.dmulloy2.net/repository/public/</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>org.spigotmc</groupId>
<artifactId>spigot-api</artifactId>
<version>1.12.2-R0.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.comphenix.protocol</groupId>
<artifactId>ProtocolLib</artifactId>
<version>4.6.0</version>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>8.0.25</version>
</dependency>
</dependencies>
</project>
Did you use the right SNAPSHOT jar? Because that should work for you and
jar tf <the snapshot>.jar | find "com/mysql/cj/jdbc/MysqlDataSource"
on Windows or
jar tf <the snapshot>.jar | grep "com/mysql/cj/jdbc/MysqlDataSource"
on *nix should find that 'missing' class in the jar
Related
I have just started with java dev. I am given a task of doing object serialization of avro format. I have broken my head trying different methods. The different IDEs and different tools, none of which have I been able to use to solve the issue, moreover they have made everything more complex and frustrating. I tried following a tutorial which didnt use an IDE per say but that was also unsuccessful as the Serialize.java class wasnt compiling. I'm presently trying to achieve the task using maven plugins and dependencies. I have just made a new Maven project on Intellij. This is my pom.xml where I have pasted the dependencies and plugins for avro format:
<?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>org.example</groupId>
<artifactId>avroTrial2</artifactId>
<version>1.0-SNAPSHOT</version>
<dependencies>
<dependency>
<groupId>org.apache.avro</groupId>
<artifactId>avro</artifactId>
<version>1.10.1</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.avro</groupId>
<artifactId>avro-maven-plugin</artifactId>
<version>1.10.1</version>
<executions>
<execution>
<phase>generate-sources</phase>
<goals>
<goal>schema</goal>
</goals>
<configuration>
<sourceDirectory>${project.basedir}/src/main/avro/</sourceDirectory>
<outputDirectory>${project.basedir}/src/main/java/</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</build>
<properties>
<maven.compiler.source>12</maven.compiler.source>
<maven.compiler.target>12</maven.compiler.target>
</properties>
</project>
The second plugin shows an error, I have done the maven syncing on intellij and thats how the error from first plugin was rectified. Now the error being shown is : "Plugin 'org.apache.maven.plugins:maven-compiler-plugin:' not found". I need to deal with this error first before I can go and get stuck on some avro error after this.
This might be the reason behind it. The configuration part in the maven compiler plugin section and the properties basically do the same thing. You have configured twice and with different versions. It should be either one of them and in general should match with the java version you are using (more details could be found here.
This is not matching
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
with
<properties>
<maven.compiler.source>12</maven.compiler.source>
<maven.compiler.target>12</maven.compiler.target>
</properties>
and only use one of them.
I have encountered same problem so what I did to resolve it is:
Navigated to File->Settings in IntelliJ
Select Plugin from left bar and then I unchecked Maven plugin
Restarted the IDE
Again clicked on Plugin and checked Maven
Restarted the IDE
I have installed protobuf 2.5.0 in my CentOs,
when i execute the command protoc --version, it yields
libprotoc 2.5.0
as output.
but Once I have pulled code from git and when I try to compile it using Maven3, the proto module throws error saying,
protoc failed error: /bin/sh: protoc: command not found
I refereed many blogs and also did try to change my bashrc path as follows,
export JAVA_HOME=/opt/java/jdk1.7.0_67
export PATH=$PATH:/opt/java/jdk1.7.0_67/bin
export PATH=$PATH:/usr/local/lib
but if I execute,
sudo yum install protobuf-compiler
it installs protobuf2.3 compiler and this particular error gets solved. But since my pom file has protobuf 2.5.0, java abstract method error arises during the next compilation. I'm stuck on how to proceed. I've spend many hrs in it, so any help is much appreciated.
my pom file for the proto module,
<?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>
<artifactId>GradPower</artifactId>
<groupId>org.screative.gardpower</groupId>
<version>1.0-SNAPSHOT</version>
</parent>
<groupId>proto</groupId>
<artifactId>proto</artifactId>
<version>1.0-SNAPSHOT</version>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>com.google.protobuf</groupId>
<artifactId>protobuf-java</artifactId>
<version>2.5.0</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>com.google.protobuf.tools</groupId>
<artifactId>maven-protoc-plugin</artifactId>
<version>0.1.10</version>
<configuration>
<protocExecutable>protoc</protocExecutable>
<protoSourceRoot>${project.basedir}/src/main/proto/</protoSourceRoot>
<languageSpecifications>
<LanguageSpecification>
<language>JAVA</language>
<outputDirectory>
${project.basedir}/target/generated-sources/protoc
</outputDirectory>
</LanguageSpecification>
</languageSpecifications>
</configuration>
<executions>
<execution>
<goals>
<goal>compile</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
<compilerArgument></compilerArgument>
</configuration>
</plugin>
</plugins>
</build>
<pluginRepositories>
<pluginRepository>
<id>dtrott</id>
<url>http://maven.davidtrott.com/repository</url>
</pluginRepository>
</pluginRepositories>
</project>
Thanks in advance.
EDIT:
I solved it. I copied protoc file from /usr/local/lib to /usr/bin
and it solved it. A silly mistake :P
You should run 'sudo ldconfig' to finish the installation.
I guessed you set LD_LIBRARY_PATH to add /usr/local/lib in your environment setting. And it doesn't take effect when building project with maven/sbt and other build tools.
Answer extracted from the Question (written by OP):
I solved it. I copied protoc file from /usr/local/lib to /usr/bin
and it solved it.
I wrote a maven plugin/mojo to generate some code. The plugin works well, and is built in Java JDK 1.8.
I am seeing an odd bit of behavior though: It builds, installs, etc just fine if I use pre-1.8 syntax, but as soon as I use a Java 8 Lambda expression, I get the following error when executing mvn clean install:
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-plugin-plugin:3.2:descriptor (default-descriptor) on project my-maven-plugin: Execution default-descriptor of goal org.apache.maven.plugins:maven-plugin-plugin:3.2:descriptor failed: 13557 -> [Help 1]
Here's my 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.my.group.id</groupId>
<artifactId>my-maven-plugin</artifactId>
<packaging>maven-plugin</packaging>
<version>1.0-SNAPSHOT</version>
<name>My Maven Mojo</name>
<url>http://maven.apache.org</url>
<properties>
<org.springframework.version>4.0.1.RELEASE</org.springframework.version>
<joda-time.version>2.3</joda-time.version>
</properties>
<dependencies>
<!-- several dependencies -->
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.2</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<!-- The following manual call to the maven-plugin plugin is necessary to get around a bug in maven 3.1.1.
If the build server gets updated to 3.2.2+ we can remove this -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-plugin-plugin</artifactId>
<version>3.2</version>
<configuration>
<!-- see http://jira.codehaus.org/browse/MNG-5346 -->
<skipErrorNoDescriptorsFound>true</skipErrorNoDescriptorsFound>
</configuration>
<executions>
<execution>
<id>mojo-descriptor</id>
<goals>
<goal>descriptor</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
<distributionManagement>
<repository>
<id>inin-release</id>
<name>ININ Release Repository</name>
<url>http://nexus.infrastructure.inintca.com/nexus/content/repositories/inin-release</url>
</repository>
<snapshotRepository>
<id>inin-snapshot</id>
<name>ININ Snapshot Repository</name>
<url>http://nexus.infrastructure.inintca.com/nexus/content/repositories/inin-snapshot</url>
</snapshotRepository>
</distributionManagement>
</project>
The issue appears in this case when I attempt to use a lambda to define a FileFilter rather than the traditional anonymous inner class.
This works:
List<File> controllerFiles = Arrays.asList(packageDirFile.listFiles(new FileFilter()
{
#Override
public boolean accept(File file)
{
return file.isFile() && file.getName().endsWith(".java");
}
}));
While this produces the aforementioned error:
List<File>
controllerFiles =
Arrays.asList(packageDirFile.listFiles(file -> file.isFile() &&
file.getName().endsWith(".java")));
Obviously given that I have a workaround this isn't critical, but the lambda is much cleaner than the anonymous inner class IMO and given that I'm working in Java 8 I'd much prefer to use it. Anybody have any tips, particularly given that I've already set skipErrorNoDescriptorsFound to true?
The note on MPLUGIN-273 says lambdas work if the build is using maven-plugin-plugin version 3.3. The error message shown references maven-plugin-plugin version 3.2 . Make sure you're using the correct version of the plugin and see if that fixes the issue.
I just realized I answered my own question. In my second comment there's a link to a Maven Jira issue, in which somebody commented that upping the maven-plugin-plugin version to 3.3 from 3.2 fixes the issue, and after trying it I discovered the same. So this:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-plugin-plugin</artifactId>
<version>3.2</version>
...
</plugin>
becomes
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-plugin-plugin</artifactId>
<version>3.3</version>
...
</plugin>
And the problem goes away.
I've got several github java projects. One of them I've manually deployed to sonatype's repository so that it gets published in maven central.
This has been a somewhat painful process in the sense that it seems to involve too many hoops to jump through and a lot of manual work and I'd like to automate that.
So I actually stopped doing that because it was just too much work. There's plenty of documentation that suggests this is possible and quite a bit that suggest that it somehow involves doing something with the nexus-staging-maven-plugin.
Unfortunately all of that documentation is (in typical maven style) skipping over the essential details that would allow me to figure out in a straightforward way the minimum amount of steps necessary that allow me to automatically publish release builds to the sonatype repository (i.e. without me manually approving things).
So, what is the blurb that needs to be present in my pom (assume a otherwise bog standard uncomplicated java project), including urls for the sonatype repository, all documentation I've found seems to insist localhost:8081 is it, and the required maven incantations to make it do a release (preferably via the mvn release plugin), have it sign the artifacts, and have it deploy the resulting artifacts to sonatype, approved and all ready to be synced to maven central, etc.
So, I'm sort of looking for the maven replacement of a "gem push" in the ruby world, which gets the job done in a convenient one liner. It's a simple case of given a jar file approved by me, how do I get it to end up in maven central with the least amount of fuss.
I'd very much appreciate some examples of pom files already setup to do this that I can copy and adapt.
Edit:
Here's my working pom file:
<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.jillesvangurp</groupId>
<artifactId>jsonj</artifactId>
<version>1.34-SNAPSHOT</version>
<name>JsonJ</name>
<description>A framework for working with json in Java the "proper" way. No mappings or model classes, it's all just lovely json, but in Java.</description>
<url>https://github.com/jillesvangurp/jsonj</url>
<licenses>
<license>
<name>MIT license</name>
<url>https://github.com/jillesvangurp/jsonj/blob/master/LICENSE</url>
<distribution>repo</distribution>
</license>
</licenses>
<scm>
<url>git://git#github.com:jillesvangurp/jsonj.git</url>
<connection>scm:git:git#github.com:jillesvangurp/jsonj.git</connection>
<developerConnection>scm:git:git#github.com:jillesvangurp/jsonj.git</developerConnection>
</scm>
<repositories>
<repository>
<id>sonatype-nexus-snapshots</id>
<name>Sonatype Nexus Snapshots</name>
<url>https://oss.sonatype.org/content/repositories/snapshots</url>
<releases>
<enabled>false</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
</repositories>
<distributionManagement>
<snapshotRepository>
<id>sonatype-nexus-snapshots</id>
<name>Sonatype Nexus Snapshots</name>
<url>https://oss.sonatype.org/content/repositories/snapshots/</url>
</snapshotRepository>
<repository>
<id>sonatype-nexus-staging</id>
<name>Nexus Release Repository</name>
<url>https://oss.sonatype.org/service/local/staging/deploy/maven2/</url>
</repository>
</distributionManagement>
<developers>
<developer>
<id>jillesvangurp</id>
<name>Jilles van Gurp</name>
<url>http://www.jillesvangurp.com</url>
<timezone>gmt+1</timezone>
<roles>
<role>Main Developer</role>
</roles>
</developer>
</developers>
<organization>
<name>www.jillesvangurp.com</name>
<url>http://jillesvangurp.com</url>
</organization>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.5.1</version>
<configuration>
<verbose>true</verbose>
<fork>true</fork>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>2.8.1</version>
<executions>
<execution>
<id>documentation</id>
<phase>prepare-package</phase>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<version>2.2</version>
<executions>
<execution>
<id>gathersource</id>
<phase>prepare-package</phase>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.sonatype.plugins</groupId>
<artifactId>nexus-staging-maven-plugin</artifactId>
<version>1.6</version>
<extensions>true</extensions>
<configuration>
<!-- The Base URL of Nexus instance where we want to stage -->
<nexusUrl>https://oss.sonatype.org/</nexusUrl>
<serverId>sonatype-nexus-staging</serverId>
</configuration>
</plugin>
</plugins>
<extensions>
<extension>
<artifactId>wagon-webdav-jackrabbit</artifactId>
<groupId>org.apache.maven.wagon</groupId>
<version>2.2</version>
</extension>
</extensions>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-release-plugin</artifactId>
<version>2.1</version>
<configuration>
<mavenExecutorId>forked-path</mavenExecutorId>
<useReleaseProfile>false</useReleaseProfile>
<arguments>-Psonatype-oss-release</arguments>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>
<profiles>
<profile>
<id>sonatype-oss-release</id>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-gpg-plugin</artifactId>
<executions>
<execution>
<id>sign-artifacts</id>
<phase>verify</phase>
<goals>
<goal>sign</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
</profiles>
<dependencies>
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>6.8.7</version>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest-all</artifactId>
<version>1.3</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.googlecode.json-simple</groupId>
<artifactId>json-simple</artifactId>
<version>1.1.1</version>
<exclusions>
<exclusion>
<artifactId>junit</artifactId>
<groupId>junit</groupId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>xom</groupId>
<artifactId>xom</artifactId>
<version>1.2.5</version>
<optional>true</optional>
</dependency>
<dependency>
<groupId>commons-lang</groupId>
<artifactId>commons-lang</artifactId>
<version>2.6</version>
</dependency>
<dependency>
<groupId>com.jillesvangurp</groupId>
<artifactId>efficientstring</artifactId>
<version>1.11</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-core</artifactId>
<version>2.2.3</version>
</dependency>
</dependencies>
</project>
The comment (#aurelien-thieriot) below put me on the right track but was not enough by itself.
In the end I took the sonatype parent pom and flattened it into my pom file.
This allows me to use the mvn release plugin normally. It uploads the artifacts to the sonatype staging repository. Then to release the artifacts, I actually needed the staging repository id.
You can find this from the repositories view in https://oss.sonatype.org/index.html#stagingRepositories.
In my case the command line became:
mvn nexus-staging:release -Ddescription="Release 1.33" -DstagingRepositoryId=comjillesvangurp-1002
Without the right id it doesn't figure it out and still fails: Sonatype Maven Staging Plugin Issue
So 95% automated but I still need to figure out the stagingRepositoryId every time.
Edit:
mvn release:perform actually tells you the id of the staging repository.
I guess you could write a script that extracts this id from the output and then passes it in to the next step. If somebody knows some mvn voodoo to make mvn release:perform do the staging release as well, it would be much appreciated.
For the convenience of Maven projects, Sonatype is providing a parent POM you can add to your project with all the basic configuration:
https://docs.sonatype.org/display/Repository/Sonatype+OSS+Maven+Repository+Usage+Guide#SonatypeOSSMavenRepositoryUsageGuide-Changesto%7B%7Bpom.xml%7D%7D
The important bits are:
<parent>
<groupId>org.sonatype.oss</groupId>
<artifactId>oss-parent</artifactId>
<version>7</version>
</parent>
And the source code repository details:
<scm>
<connection>scm:svn:http://foo.googlecode.com/svn/trunk/</connection>
<developerConnection>scm:svn:https://foo.googlecode.com/svn/trunk/</developerConnection>
<url>http://foo.googlecode.com/svn/trunk/</url>
</scm>
You will also need GPG to be install on your computer (Required to sign the packages) and our settings.xml correctly filled with your credentials:
<servers>
<server>
<id>sonatype-nexus-snapshots</id>
<username>your-jira-id</username>
<password>your-jira-pwd</password>
</server>
<server>
<id>sonatype-nexus-staging</id>
<username>your-jira-id</username>
<password>your-jira-pwd</password>
</server>
</servers>
After that, you should be able to use the two steps release:
$ mvn release:prepare
$ mvn release:perform
Unfortunately, I don't know any way of automate the manual approval part of the process (In oss.sonatype.org). But that should already save you some times.
The documentation, as shown above, is probably a bit convoluted but is very complete and gives you all you need to know for various scenarios.
EDIT:
In fact I think I am wrong and there is a part on automate approval process. Interesting.
And for this part you are right, the details are quite limited. Though, I hope the first part of the configuration already helps you a little bit. I need to look further into this staging stuff (Or maybe someone else would have already done it !)
EDIT_AGAIN:
I need to actually try it but it would sound like something as follow:
<plugins>
<plugin>
<groupId>org.sonatype.plugins</groupId>
<artifactId>nexus-staging-maven-plugin</artifactId>
<version>1.6</version>
<extensions>true</extensions>
<configuration>
<!-- The Base URL of Nexus instance where we want to stage -->
<nexusUrl>https://oss.sonatype.org/service/local/staging/deploy/maven2/</nexusUrl>
<serverId>sonatype-nexus-staging</serverId>
</configuration>
</plugin>
</plugins>
According to the documentation, the deploy should be replaced by the right staging workflow (Including the close) and it would left the latest step:
$ mvn nexus-staging:release -Ddescription="Yippie!"
TO BE TESTED...
So 95% automated but I still need to figure out the stagingRepositoryId every time.
You can use mvn nexus-staging:rc-list
Specifically, by doing mvn release:rc-list and using grep or whatever to filter the output from that by some form of the group ID or other substring that you know the stagingRepositoryId to be, you can determine the full stagingRepositoryId value
For example, the group ID for my project is nu.validator and my stagingRepositoryId values are all in the form nuvalidator-NNNN where the NNNN part is a number that started from 1000 with my first release and that the system increments by 1 each time I release; so nuvalidator-1000, nuvalidator-1001, and so on.
So in the python script I use for my build, I just do this:
output = subprocess.check_output("mvn nexus-staging:rc-list -DnexusUrl=https://oss.sonatype.org/ -DserverId=ossrh")
for line in output.split('\n'):
if "nuvalidator" in line:
stagingRepositoryId = "nuvalidator-" + line[8:23]
...
That's because the relevant lines returned in the mvn nexus-staging:rc-list output are in the form:
...
[INFO] central_bundles-3514 OPEN Implicitly created (auto staging).
[INFO] central_bundles-3515 OPEN Implicitly created (auto staging).
[INFO] central_bundles-3521 OPEN Implicitly created (auto staging).
[INFO] nuvalidator-1008 OPEN Implicitly created (auto staging).
...
I want to start a project for Android but i really like to build it using Maven. Does Google provide support for Maven or plan to support it? It would be great if anybody know at least an archetype for Maven that I can use meanwhile. Thanks in advance.
Seems like there is a maven plugin for that :-)
What I really wanted was an article like this, but i found it after the question was answered.
Update:
People at SpringSource did a Spring Android project that supports the usage of the Spring Framework in an Android environment and have Maven support. I will give it a try.
Here is an article about Spring Android and Maven using Eclipse 3.6 and Android SDK 9, split in two parts:
First part
Second part
The Android Maven plugin has been updated to support changes made in the Android SDK r14 release. You will need to adjust your POM to use the new version. I experienced an out of memory error with the new version when building my app, so note the dex jvmArguments section to allow for more available memory.
<plugin>
<groupId>com.jayway.maven.plugins.android.generation2</groupId>
<artifactId>android-maven-plugin</artifactId>
<version>3.0.0-alpha-13</version>
<configuration>
<sdk>
<platform>${android-platform}</platform>
</sdk>
<dex>
<jvmArguments>
<jvmArgument>-Xms256m</jvmArgument>
<jvmArgument>-Xmx512m</jvmArgument>
</jvmArguments>
</dex>
<deleteConflictingFiles>true</deleteConflictingFiles>
<undeployBeforeDeploy>true</undeployBeforeDeploy>
</configuration>
<extensions>true</extensions>
</plugin>
The latest version of the Android Configurator (m2e-android) for Eclipse also supports the changes in r14. Lastly, I've posted a follow up blog on the SpringSource site called Updated Maven Support for Android Projects, which goes over these updates to the tools.
Here is what I did to add maven support to an existing android project in Eclipse. I installed the 'm2e' plugin via the Eclipse market place. Then I installed the 'm2e-android' plugin. At the moment it is called 'Android Configurator for M2E' in Eclipse market place. After installing the two plugins and restarting Eclipse, right click on an existing android project-->Configure-->Convert to Maven Project. Choose a unique group id and an artifact id for your project then click finish. Copy the following contents to the pom.xml of the project and replace all the existing contents. Change the value of the 'version' tag under 'dependencies' to the SDK version you are using. Also change the value of the 'platform' tag near the end of the file to the value of your platform. Do not forget to also change the groupId, artifactId and name of the 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/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.myproject</groupId>
<artifactId>MyProject</artifactId>
<version>0.1.0-SNAPSHOT</version>
<packaging>apk</packaging>
<name>MyProject</name>
<dependencies>
<dependency>
<groupId>com.google.android</groupId>
<artifactId>android</artifactId>
<version>2.3.3</version>
<scope>provided</scope>
</dependency>
</dependencies>
<build>
<finalName>${project.artifactId}</finalName>
<sourceDirectory>src</sourceDirectory>
<pluginManagement>
<plugins>
<plugin>
<groupId>com.jayway.maven.plugins.android.generation2</groupId>
<artifactId>android-maven-plugin</artifactId>
<version>3.3.0</version>
<extensions>true</extensions>
</plugin>
</plugins>
</pluginManagement>
<plugins>
<plugin>
<groupId>com.jayway.maven.plugins.android.generation2</groupId>
<artifactId>android-maven-plugin</artifactId>
<configuration>
<sdk>
<!-- platform or api level (api level 4 = platform 1.6)-->
<platform>10</platform>
</sdk>
</configuration>
</plugin>
</plugins>
</build>
</project>
After that right click on the project-->Maven-->Update Project. If Eclipse is complaining about errors in the xml, you may want to install maven then run
mvn clean install
from the console in the folder that contains the pom.xml file.
as #Riduidel said before, you can use com.jayway.maven.plugins.android.generation2 plugin. Note, that you don't need download any plugins, you need to have just the maven for using this plugin.
How I did it:
manually add pom.xml to your android project (to the root of project).
download apache-maven-3.1.1 and add your bin folder ( ex D:\java\apache-maven-3.1.1\bin;) to path in Environment Variables.
configure settings.xml in [Your_maven_path]\conf with next:
<pluginGroups>
<pluginGroup>com.jayway.maven.plugins.android.generation2</pluginGroup>
</pluginGroups>
Add content to pom.xml. My example:
<?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.example.ENumbers</groupId>
<artifactId>ENumbers</artifactId>
<version>1.0</version>
<packaging>apk</packaging>
<name>MainApp</name>
<properties>
<platform.version>2.2.1</platform.version>
</properties>
<dependencies>
<dependency>
<groupId>com.google.android</groupId>
<artifactId>android</artifactId>
<version>${platform.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.simpleframework</groupId>
<artifactId>simple-xml</artifactId>
<version>2.7.1</version>
<scope>provided</scope>
<exclusions>
<exclusion>
<artifactId>xpp3</artifactId>
<groupId>xpp3</groupId>
</exclusion>
<exclusion>
<artifactId>stax-api</artifactId>
<groupId>stax</groupId>
</exclusion>
<exclusion>
<artifactId>stax</artifactId>
<groupId>stax</groupId>
</exclusion>
<exclusion>
<artifactId>spring-web</artifactId>
<groupId>org.springframework</groupId>
</exclusion>
<exclusion>
<artifactId>commons-logging</artifactId>
<groupId>commons-logging</groupId>
</exclusion>
</exclusions>
</dependency>
</dependencies>
<build>
<sourceDirectory>src</sourceDirectory>
<plugins>
<plugin>
<groupId>com.jayway.maven.plugins.android.generation2</groupId>
<artifactId>android-maven-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<androidManifestFile>${project.basedir}/AndroidManifest.xml</androidManifestFile>
<assetsDirectory>${project.basedir}/assets</assetsDirectory>
<resourceDirectory>${project.basedir}/res</resourceDirectory>
<nativeLibrariesDirectory>${project.basedir}/src/main/native</nativeLibrariesDirectory>
<sdk>
<path>
D:\Program Files\Android\android-sdk
</path>
<platform>22</platform>
</sdk>
<undeployBeforeDeploy>true</undeployBeforeDeploy>
</configuration>
<extensions>true</extensions>
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
</plugins>
</build>
</project>
Look at important <packaging>, <build> nodes, it's content and com.google.android dependency.
Now you can open Maven window in your IDE. For Intellij Idea I do it next:
Edit->Tool Windows->Maven and add your pom.xml for initializing maven directory.
That's all.