Overwrite archetypes in Maven - maven-2

I'm having some trouble using Maven for my archetypes and I will need to overwrite some. I launch an instruction that does an archetype:generate in an archetype already existing directory.
Is there a parameter that let's me overwrite existing archetypes?
I have search the maven definitve guide but it states that the only parameters accepted are:
-DgroupId
-DartifactId
-Dversion
-DpackageName
-DarchetypeGroupId
-DarchetypeArtifactId
-DarchetypeVersion
-DinteractiveMode
I could just search the directory and delete the files, but this proccess is going to be done automatically (so no human involved, no brains involved) and I wouldn't like he machine deleting things around.
Thanks for all!
Edit: I almost forgot, here is some maven trace:
[INFO] Scanning for projects...
[INFO] Searching repository for plugin with prefix: 'archetype'.
[INFO] ------------------------------------------------------------------------
[INFO] Building Maven Default Project
[INFO] task-segment: [archetype:generate] (aggregator-style)
[INFO] ------------------------------------------------------------------------
[INFO] Preparing archetype:generate
[INFO] No goals needed for project - skipping
[INFO] Setting property: classpath.resource.loader.class => 'org.codehaus.plexus.velocity.ContextClassLoaderResourceLoader'.
[INFO] Setting property: velocimacro.messages.on => 'false'.
[INFO] Setting property: resource.loader => 'classpath'.
[INFO] Setting property: resource.manager.logwhenfound => 'false'.
[INFO] [archetype:generate {execution: default-cli}]
[INFO] Generating project in Batch mode
[INFO] Archetype defined by properties
[INFO] ----------------------------------------------------------------------------
[INFO] Using following parameters for creating OldArchetype: archetype-foo-lib:1.0
[INFO] ----------------------------------------------------------------------------
[INFO] Parameter: groupId, Value: foo.tecnologia
[INFO] Parameter: packageName, Value: foo.tecnologia
[INFO] Parameter: basedir, Value: C:\temp\Desarrollo
[INFO] Parameter: package, Value: foo.tecnologia
[INFO] Parameter: version, Value: 1.0
[INFO] Parameter: artifactId, Value: Foo-Lib-Test
[ERROR] Directory Foo-Lib-Test already exists - please run from a clean directory
org.apache.maven.archetype.old.ArchetypeTemplateProcessingException: Directory Foo-Lib-Test already exists - please run from a clean directory
at org.apache.maven.archetype.old.DefaultOldArchetype.createArchetype(DefaultOldArchetype.java:242)
at org.apache.maven.archetype.generator.DefaultArchetypeGenerator.processOldArchetype(DefaultArchetypeGenerator.java:253)
at org.apache.maven.archetype.generator.DefaultArchetypeGenerator.generateArchetype(DefaultArchetypeGenerator.java:143)
at org.apache.maven.archetype.generator.DefaultArchetypeGenerator.generateArchetype(DefaultArchetypeGenerator.java:286)
at org.apache.maven.archetype.DefaultArchetype.generateProjectFromArchetype(DefaultArchetype.java:69)
at org.apache.maven.archetype.mojos.CreateProjectFromArchetypeMojo.execute(CreateProjectFromArchetypeMojo.java:184)
at org.apache.maven.plugin.DefaultPluginManager.executeMojo(DefaultPluginManager.java:490)
at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoals(DefaultLifecycleExecutor.java:694)
at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeStandaloneGoal(DefaultLifecycleExecutor.java:569)
at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoal(DefaultLifecycleExecutor.java:539)
at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoalAndHandleFailures(DefaultLifecycleExecutor.java:387)
at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeTaskSegments(DefaultLifecycleExecutor.java:284)
at org.apache.maven.lifecycle.DefaultLifecycleExecutor.execute(DefaultLifecycleExecutor.java:180)
at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:328)
at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:138)
at com.foo.model.CSMavenCli.main(CSMavenCli.java:391)
at com.foo.model.MavenAdmin.generateArchetype(MavenAdmin.java:399)
at com.foo.model.ValidarPom.validarPom(ValidarPom.java:167)
at com.foo.prueba.GenerarPOM.execute(GenerarPOM.java:93)
at org.apache.struts.chain.commands.servlet.ExecuteAction.execute(ExecuteAction.java:58)
at org.apache.struts.chain.commands.AbstractExecuteAction.execute(AbstractExecuteAction.java:67)
at org.apache.struts.chain.commands.ActionCommandBase.execute(ActionCommandBase.java:51)
at org.apache.commons.chain.impl.ChainBase.execute(ChainBase.java:191)
at org.apache.commons.chain.generic.LookupCommand.execute(LookupCommand.java:305)
at org.apache.commons.chain.impl.ChainBase.execute(ChainBase.java:191)
at org.apache.struts.chain.ComposableRequestProcessor.process(ComposableRequestProcessor.java:283)
at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1913)
at org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:462)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:647)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:269)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:188)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:172)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:117)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:108)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:174)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:873)
at org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:665)
at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:528)
at org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:81)
at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:689)
at java.lang.Thread.run(Unknown Source)
[INFO] ------------------------------------------------------------------------
[ERROR] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] : org.apache.maven.archetype.old.ArchetypeTemplateProcessingException: Directory Foo-Lib-Test already exists - please run from a clean directory
Directory Foo-Lib-Test already exists - please run from a clean directory
[INFO] ------------------------------------------------------------------------
[INFO] For more information, run Maven with the -e switch
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1 second
[INFO] Finished at: Fri Apr 09 10:01:33 CEST 2010
[INFO] Final Memory: 15M/28M
[INFO] ------------------------------------------------------------------------

I guess you would have to check out the archetype's sources. e.g.
http://svn.apache.org/viewvc/maven/archetype/tags/maven-archetype-quickstart-1.1
apply your changes and run mvn install
that said, you should usually not do it this way
for further reference:
http://maven.apache.org/guides/mini/guide-creating-archetypes.html

I want to override files when regenerating an archetype - similar to your requirements, a user can regenerate a project with different parameters. In my case, I am generating an entire REST stack from a model, and as I make changes to the archetype itself I want to iteratively regenerate all the code.
Part of the reason I want to do this is to leave the IntelliJ project files intact between regens - so that I do not have to re-import the generated project into IntelliJ.
The maven archetype plugin does not override files and does not have an option to enable that.
The solution I found is to delete all files under the generated project except the IntelliJ .iml project files, and leave .idea and all directories intact. Then the archetype plugin will work. I call the archetype plugin from a script and do the delete in that. If 'pp' is the name of the directory containing the project to regenerate:
# This should leave IntelliJ project files intact accross regens.
find pp -type d -name 'target' -exec rm -fR {} \;
find pp -type d -name 'generated' -exec rm -fR {} \;
find pp -type f -not -path '*/.idea/*' -not -name '*.iml' -exec rm {} \;
You should be able to come up with some variation on this to achieve what you want.

There is only a poor man solution:
Simply create the archetype to another directory and then copy that over the existing project to update.

Related

Getting start with Maven

I am very new to Maven.I have installed the maven on my local machine.
After installation for trial basis i was trying to execute mvn archetype:generate -DarchetypeGroupId=org.apache.maven.archetypes -DgroupId=com.mycompany.app -DartifactId=my-app
for that i am getting below error message.
C:\work\maven2.2\bin>mvn archetype:generate -DarchetypeGroupId=org.apache
.maven.archetypes -DgroupId=com.mycompany.app -DartifactId=my-app
[INFO] Scanning for projects...
[INFO] Searching repository for plugin with prefix: 'archetype'.
[INFO] org.apache.maven.plugins: checking for updates from central
[WARNING] repository metadata for: 'org.apache.maven.plugins' could not be retri
eved from repository: central due to an error: Error transferring file: repo1.ma
ven.org
[INFO] Repository 'central' will be blacklisted
[INFO] ------------------------------------------------------------------------
[ERROR] BUILD ERROR
[INFO] ------------------------------------------------------------------------
[INFO] The plugin 'org.apache.maven.plugins:maven-archetype-plugin' does not exi
st or no valid version could be found
[INFO] ------------------------------------------------------------------------
[INFO] For more information, run Maven with the -e switch
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 2 seconds
[INFO] Finished at: Tue Aug 30 11:45:49 IST 2011
[INFO] Final Memory: 1M/59M
[INFO] ------------------------------------------------------------------------
Can any one help me if i need to have a prerequisite setting for the same?
Thanks in advance. :)
It's comand is correct and on my computer run correctly. But you have Error transferring file. So on this branch you may read about this error.
EDIT:
Tutorials:
First of all read this article : maven in 5 minutes
For more information : Maven Getting Started Guide
The second article will give you all you need to understend maven.

Maven adds '-windows' to the artifact name when downloading a snapshot artifact

I have added a bunch of artifacts to my local Nexus Maven repository.
When I build my project I get the following error:
[INFO] Scanning for projects...
[INFO] ------------------------------------------------------------------------
[INFO] Building pronto-web Java EE 6 Webapp
[INFO] task-segment: [verify]
[INFO] ------------------------------------------------------------------------
[INFO] [resources:resources {execution: default-resources}]
[WARNING] Using platform encoding (Cp1252 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] Copying 4 resources
[INFO] [compiler:compile {execution: default-compile}]
[WARNING] File encoding has not been set, using platform encoding Cp1252, i.e. build is platform dependent!
[INFO] Compiling 1 source file to C:\Source\Pronto\pronto\pronto-web\target\classes
[INFO] [antrun:run {execution: remove-javax}]
[INFO] Executing tasks
[INFO] Executed tasks
[INFO] [gwt:compile {execution: default}]
[INFO] using GWT jars from project dependencies : 20100714-SNAPSHOT
[WARNING] You should not declare gwt-dev as a project dependency. This may introduce complex dependency conflicts
Downloading: http ://mercury:8980/nexus/content/groups/public-snapshots/com/google/gwt/gwt-dev/20100714-SNAPSHOT/gwt-dev-20100714-20100715.053026-1-windows.jar
[INFO] ------------------------------------------------------------------------
[ERROR] BUILD ERROR
[INFO] ------------------------------------------------------------------------
[INFO] artifact not found - Unable to locate resource in repository
Try downloading the file manually from the project website.
Then, install it using the command:
mvn install:install-file -DgroupId=com.google.gwt -DartifactId=gwt-dev -Dversion=20100714-20100715.053026-1 -Dclassifier=windows -Dpackaging=jar -Dfile=/path/to/file
Alternatively, if you host your own repository you can deploy the file there:
mvn deploy:deploy-file -DgroupId=com.google.gwt -DartifactId=gwt-dev >-Dversion=20100714-20100715.053026-1 -Dclassifier=windows -Dpackaging=jar -Dfile=/path/to/file -Durl=[url] -DrepositoryId=[id]
com.google.gwt:gwt-dev:jar:20100714-20100715.053026-1
from the specified remote repositories:
releases (http://mercury:8980/nexus/content/groups/public),
all (http://mercury:8980/nexus/content/groups/all),
snapshots (http://mercury:8980/nexus/content/groups/public-snapshots)
http ://mercury:8980/nexus/content/groups/public-snapshots/com/google/gwt/gwt-dev/20100714-SNAPSHOT/gwt-dev-20100714-20100715.053026-1-windows.jar
[INFO] ------------------------------------------------------------------------
[INFO] For more information, run Maven with the -e switch
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 8 seconds
[INFO] Finished at: Thu Jul 15 08:57:29 CEST 2010
[INFO] Final Memory: 50M/614M
[INFO] ------------------------------------------------------------------------
Has anyone an idea why maven thinks there should be '-windows' added to the artifact name?
(Downloading: http ://mercury:8980/nexus/content/groups/public-snapshots/com/google/gwt/gwt-dev/20100714-SNAPSHOT/gwt-dev-20100714-20100715.053026-1-windows.jar)
If I browse the repository it contains the artifact but without the '-windows' suffix.
Older versions of this artifact were platform dependent and had 'windows' or 'linux' or 'mac' as classifier but recent versions are platform independent and I don't have any such classifier in my poms.
PS:
I added a space in each URL between the protocol and the colon because I didn't yet receive enough reputation to post links.
The following dependency must be declared somewhere, very likely as a transitive dependency:
<dependency>
<groupId>com.google.gwt</groupId>
<artifactId>gwt-dev</artifactId>
<version>20100714-SNAPSHOT</version>
<classifier>windows</classifier>
<dependency>
I suspect a bad pom if artifacts are not platform dependent anymore.
Is there any more recent snapshot you can use?

I am unable to run maven2

I am not able to run Maven 2.1. I get following Error while running:
****************************************************************
naresh#HYRDSRVIHUB01:~/.m2> mvn archetype:create -DarchetypeGroupId=org.apache.maven.archetypes -DgroupId=com.mycompany.app -DartifactId=my-app
[INFO] Scanning for projects...
[INFO] Searching repository for plugin with prefix: 'archetype'.
[INFO] org.apache.maven.plugins: checking for updates from central
[WARNING] repository metadata for: 'org.apache.maven.plugins' could not be retrieved from repository: central due to an error: Error transferring file: Connection refused
[INFO] Repository 'central' will be blacklisted
[INFO] ------------------------------------------------------------------------
[ERROR] BUILD ERROR
[INFO] ------------------------------------------------------------------------
[INFO] The plugin 'org.apache.maven.plugins:maven-archetype-plugin' does not exist or no valid version could be found
[INFO] ------------------------------------------------------------------------
[INFO] For more information, run Maven with the -e switch
[INFO] ------------------------------------------------------------------------
[INFO] Total time: < 1 second
[INFO] Finished at: Thu Jul 22 17:59:02 IST 2010
[INFO] Final Memory: 3M/240M
[INFO] ------------------------------------------------------------------------
******************************************************************
Help me to get rid of it.
As already pointed out, you are running Maven. However, depending on what you're asking Maven to do, Maven might have to download libraries from a remote repository: plugins, dependencies, etc that are then stored in your local repository and downloading libraries from a remote repository requires a connection.
If you start using Maven with an empty local repository, this is something you can't avoid and you'll have to let Maven download what it needs first.
Sure, you can run Maven offline (using the -o or --offline command line optionsbut this will work only if you already have the required stuff in your local repository.
Oh, and by the way, I'm not sure it's really wise to create a project under your ~/.m2 directory. You should run archetype:create from another location, e.g. ~/Projects.
Your running maven, the issue is either with your connection it seems to be getting rejected by the maven repo:
[WARNING] repository metadata for: 'org.apache.maven.plugins' could not be retrieved from repository: central due to an error: Error transferring file: Connection refused

Maven: Cannot get the help goals working (clean:help, compiler:help, etc)

I am new in Maven. Do you know what I am doing wrong (see below)?
mvn -e clean:help.
+ Error stacktraces are turned on.
[INFO] Scanning for projects...
[INFO] Searching repository for plugin with prefix: 'clean'.
[INFO] ------------------------------------------------------------------------
[ERROR] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Required goal not found: clean:help in org.apache.maven.plugins:maven-clean-plugin:2.2
[INFO] ------------------------------------------------------------------------
[INFO] Trace
org.apache.maven.BuildFailureException: Required goal not found: clean:help in org.apache.maven.plugins:maven-clean-plugin:2.2
at org.apache.maven.lifecycle.DefaultLifecycleExecutor.getMojoDescriptor(DefaultLifecycleExecutor.java:1867)
at org.apache.maven.lifecycle.DefaultLifecycleExecutor.segmentTaskListByAggregationNeeds(DefaultLifecycleExecutor.java:462)
at org.apache.maven.lifecycle.DefaultLifecycleExecutor.execute(DefaultLifecycleExecutor.java:175)
at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:328)
The version of the plugin you are using on the command line (2.2) does not have the clean:help goal (since 2.3). Try this instead:
mvn org.apache.maven.plugins:maven-clean-plugin:2.4:help
I think you want:
mvn help:describe -Dcmd=clean
which gives:
[INFO] [help:describe {execution: default-cli}]
[INFO] 'clean' is a lifecycle with the following phases:
* pre-clean: Not defined
* clean: org.apache.maven.plugins:maven-clean-plugin:clean
* post-clean: Not defined
See here for more details and examples. The same applies for compile.
mvn help:describe -Dcmd=compile

maven dependency unable to read lib from the dependency jar

I have projects A & B where Project B is dependent on A. When I run mvn clean install in the command prompt, Project A compiles well and it produces the dependent jar for Project B in the maven local repository. During the compilation of Project B, I am getting a compilation error for a dependency listed in project B's POM. I have checked the classpath, versions and they are fine. The error I am seeing is mentioned below:
Project A
[INFO] Building tsscommon-ifc
[INFO] task-segment: [clean, install]
[INFO] ------------------------------------------------------------------------
[INFO] [clean:clean]
[INFO] Deleting directory V:\dhs_tss_build_view\dhs_tssproject\tss\tsscommon-ifc\target
[INFO] [resources:resources]
[INFO] Using default encoding to copy filtered resources.
[INFO] [compiler:compile]
[INFO] Compiling 455 source files to V:\dhs_tss_build_view\dhs_tssproject\tss\tsscommon-ifc\target\classes
[INFO] [resources:testResources]
[INFO] Using default encoding to copy filtered resources.
[INFO] [compiler:testCompile]
[INFO] Not compiling test sources
[INFO] [surefire:test]
[INFO] Tests are skipped.
[INFO] [jar:jar]
[INFO] Building jar: V:\dhs_tss_build_view\dhs_tssproject\tss\tsscommon-ifc\target
\tsscommon-ifc-2.39.00-SNAPSHOT.jar
[INFO] [install:install]
[INFO] Installing V:\dhs_tss_build_view\dhs_tssproject\tss\tsscommon-ifc\target\tsscommon-ifc-2.39.00-SNAPSHOT.jar to C:\Documents and Settings\pwvxd35\.m2\repository\us\mn\state\dhs\tss\common\tsscommon-ifc\2.39.00-SNAPSHOT\tsscommon-ifc-2.39.00-SNAPSHOT.jar
This is fine.
Project B
[INFO] Building tsscommon-server
[INFO] task-segment: [clean, install]
[INFO] ------------------------------------------------------------------------
[INFO] [clean:clean]
[INFO] Deleting directory V:\dhs_tss_build_view\dhs_tssproject\tss\tsscommon-server\target
[INFO] [resources:resources]
[INFO] Using default encoding to copy filtered resources.
[INFO] [compiler:compile]
[INFO] Compiling 137 source files to V:\dhs_tss_build_view\dhs_tssproject\tss\tsscommon-server\target\classes
[INFO] ------------------------------------------------------------------------
[ERROR] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Compilation failure
V:/dhs_tss_build_view/dhs_tssproject/tss/tsscommon-server/src/main/java/us/mn/state/dhs/tss/common/oblix/da/wsdl/OblixLoginAccess.java:[51,60] cannot find symbol
symbol : class BusinessException
location: class us.mn.state.dhs.tss.common.oblix.da.wsdl.OblixLoginAccess
Can anyone help with this issue?
The error is
OblixLoginAccess.java:[51,60] cannot find symbol
symbol : class BusinessException
location: class us.mn.state.dhs.tss.common.oblix.da.wsdl.OblixLoginAccess
This simply means that there is a class BusinessException referenced in the code for OblixLoginAccess at line 51, character 60.
The symbol cannot be found on the compile classpath.
This may or may not have anything to do with dependencies of Project B on Project A. You need to find out where that class is supposed to be, and make sure it is there.