Coder Social home page Coder Social logo

kaspersorensen / dotnet-maven-plugin Goto Github PK

View Code? Open in Web Editor NEW
25.0 5.0 15.0 155 KB

A Maven plugin for building dotnet projects based on project.json

License: Apache License 2.0

C# 4.14% Java 95.86%
dotnet maven-plugin maven netcore csproj

dotnet-maven-plugin's Introduction

dotnet-maven-plugin

A Maven plugin for building dotnet projects based on .csproj or project.json files.

This plugin lets you use the power of Maven to drive .NET core builds.

Build Status: Linux

Features

  • Drives the invocation of dotnet and nuget command line tools for build, test, deploy of .NET core projects.
  • Runs unittests via dotnet test on projects that have a defined Test Runner.
  • Offers a mvn clean option which arguably is currently missing from the dotnet CLI tools.
  • Propagates versioning scheme from Maven parent to the .csproj or project.json files of the modules.
  • Supports two project layouts: A pom-per-dotnet-module or a single-pom-for-all-dotnet-modules approach. See example projects.
  • The plugin has Maven extensions, allowing it to be idiomatically bound to standard Maven phases by declaring certain packging types:
  • <packaging>dotnet</packaging> will bind relevant Maven phases for dotnet component and application projects, including dotnet pack, dotnet publish and dotnet nuget add.
    • If a <repository> element is defined in the projects configuration, dotnet nuget push is also bound to the mvn deploy phase.
  • <packaging>dotnet-library</packaging> will bind relevant Maven phases for dotnet class libraries, i.e. excluding dotnet publish.
  • <packaging>dotnet-test</packaging> will bind relevant Maven phases for dotnet test-only projects, including dotnet test.
  • <packaging>dotnet-integration-test</packaging> will bind Maven phase integration-test to dotnet test and Maven phase to verify to the gathering/evaluation of those results, allowing for post-integration-test clean-up tasks to take place exiting on test failures.
  • All above packaging types also have clean, restore, build bindings

Installing

The plugin leverages the dotnet (required) and nuget (optional) command line tools, which have to be installed prior to usage of the plugin.

The simples use-case it to simply define your project with the packaging type, dotnet and enabled it with a plugin in pom.xml like this:

<project>
  [...]
  <packaging>dotnet</packaging>

  [...]
  <build>
    <plugins>
      <plugin>
        <groupId>org.eobjects.build</groupId>
        <artifactId>dotnet-maven-plugin</artifactId>
        <version>0.24</version>
        <extensions>true</extensions>
      </plugin>
    </plugins>
  </build>
  [...]
</project>

Configuration

Should you want to, you can configure many aspects of the dotnet and nuget invocations. The following should provide a handy overview by example:

<plugin>
  <groupId>org.eobjects.build</groupId>
  <artifactId>dotnet-maven-plugin</artifactId>
  <version>0.23</version>
  <extensions>true</extensions>
  <configuration>
    <buildConfiguration>Release</buildConfiguration>
    <buildEnabled>true</buildEnabled>
    <cleanEnabled>true</cleanEnabled>
    <environment>
      <MY_ENVVAR_1>hello</MY_ENVVAR_1>
      <MY_ENVVAR_2>world</MY_ENVVAR_2>
    </environment>
    <integrationTestRunEnabled>true</integrationTestRunEnabled>
    <integrationTestVerifyEnabled>true</integrationTestVerifyEnabled>
    <nugetAddEnabled>true</nugetAddEnabled>
    <nugetAddSource>~/.nuget/Packages</nugetAddSource>
    <nugetPushEnabled>true</nugetPushEnabled>
    <packEnabled>true</packEnabled>
    <packOutput>bin</packOutput>
    <publishEnabled>true</publishEnabled>
    <publishOutput>bin/my-publish-output</publishOutput>
    <repository>https://path/to/repository</repository>
    <restoreEnabled>true</restoreEnabled>
    <testEnabled>true</testEnabled>
  </configuration>
</plugin>

Take a look at the Example projects for more inspiration.

dotnet-maven-plugin's People

Contributors

charbull avatar kaspersorensen avatar randylarson avatar satlarson avatar shawnkao-quadient avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

dotnet-maven-plugin's Issues

does not build with Java 1.7

Hello

The src/test/java/org.eobjects.build.CsProjFileTest is using indirectly the java.util.function.Predicate which is only avalable starting from Java 1.8. Thus the project dotnet-maven-plugin_plugin does not build.

Better way to control/sync versions

Right now the pom.xml version gets inserted as a "suffix" instead of the * symbol in project.json.

Ideally the pom.xml version should somehow dictate the version that gets published by dotnet/nuget/project.json.

Show executed commands when in debug mode (-X)

It would be really handy for debugging purposes if the executed command lines (eg. dotnet build --flags.. etc) would be printed. To prevent spam during the build, perhaps only when run in debug mode (when Maven's -X flag is specified).

add a sourceDirectory option

Hi

When using a code generator of c# code like JavaCC under maven, the c# is by default located in target/generated-sources/javacc, but the plugin does not seem to take this directory into account. So could the dotnet-maven-plugin check for c# code in the so called target directory or could be an options added to specify where are the c# code like sourceDirectory for exmaple.

Add support for F#

Version 0.24, new fsproj build files

Seems like neither the solution file .sln nor the .fsproj files are inspected. Error reported:

[ERROR] Failed to execute goal org.eobjects.build:dotnet-maven-plugin:0.24:restore (default-restore) on project FsSonarRunner: Could not find any directories with a project/build file. -> [Help 1]

API KEY argument support to push to a private myget repo

Hello,

Is there a way to pass the API KEY argument when pushing to a private myget repo?

Something similar to:

run ..\.nuget\nuget push *.nupkg <API_KEY> -Source https://www.myget.org/F/<FEED_NAME>/api/v2/package

I took a look at the code but not sure where to change in this class

Any suggestions?

Thank you

dotnet 1.0.4 and xaml?

I was looking using this plugin in trying to build this sample
https://github.com/MicrosoftEdge/MicrosoftEdge-Extensions-Demos/tree/master/SecureInput

I got stuck on the AppContainerExe and UniversalWindows UAP.
Seemed to be getting stuck on not finding xaml targets in dotnet folders, I think I found eventually that it is just not supported yet for dotnet core.
Seemed to be targeting older VS14 instead of VS15 (2017) but attempting to force version setting min didn't resolve. I didn't see anything for the plugin that would allow to specify, only setting in csproj.

Any hints?

Also tried migrating to new csproj format but couldn't get it to accept UAP build fully and SDKReference wasn't resolving.

mvn install tries to add non-packable projects

[ERROR] Failed to execute goal org.eobjects.build:dotnet-maven-plugin:0.23:nuget-add (default-nuget-add) on project csharp-sdk: Command [nuget add] failed!: Could not find NuGet package! ModuleDir=/Users/user/csharp-sdk/project.test, PackageDir=/Users/user/csharp-sdk/project.test/bin, PackOutput=bin -> [Help 1]

Create more examples of use

For example make these three examples:

  • A multi-module project with just one parent pom.xml (existing example)
  • A multi-module project with a regular parent-pom one pom.xml per module
  • Using dotnet-maven-plugin in one module only, combining with other builds

mvn install -> nuget add fails

Coming from a Java world needing to do devops tooling for dotnet projects I am looking into using your plugin to make the projects easily usable with existing Java tooling, including the JIB maven plugin for creating and pushing docker images on hosts without docker.

"mvn clean install" on an existing "X" + "X_test" project gave me the following error. Is this a simple configuration issue or am I using the plugin incorrectly?

org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.eobjects.build:dotnet-maven-plugin:0.24:nuget-add (default-nuget-add) on project operationa-inforation-ms: Command [nuget add] failed!
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:215)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:156)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:148)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:117)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:81)
    at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build (SingleThreadedBuilder.java:56)
    at org.apache.maven.lifecycle.internal.LifecycleStarter.execute (LifecycleStarter.java:128)
    at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:305)
    at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:192)
    at org.apache.maven.DefaultMaven.execute (DefaultMaven.java:105)
    at org.apache.maven.cli.MavenCli.execute (MavenCli.java:956)
    at org.apache.maven.cli.MavenCli.doMain (MavenCli.java:288)
    at org.apache.maven.cli.MavenCli.main (MavenCli.java:192)
    at jdk.internal.reflect.NativeMethodAccessorImpl.invoke0 (Native Method)
    at jdk.internal.reflect.NativeMethodAccessorImpl.invoke (NativeMethodAccessorImpl.java:62)
    at jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke (DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke (Method.java:566)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced (Launcher.java:282)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launch (Launcher.java:225)
    at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode (Launcher.java:406)
    at org.codehaus.plexus.classworlds.launcher.Launcher.main (Launcher.java:347)
Caused by: org.apache.maven.plugin.MojoFailureException: Command [nuget add] failed!
    at org.eobjects.build.DotnetNugetAddMojo.execute (DotnetNugetAddMojo.java:43)
    at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo (DefaultBuildPluginManager.java:137)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:210)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:156)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:148)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:117)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:81)
    at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build (SingleThreadedBuilder.java:56)
    at org.apache.maven.lifecycle.internal.LifecycleStarter.execute (LifecycleStarter.java:128)
    at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:305)
    at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:192)
    at org.apache.maven.DefaultMaven.execute (DefaultMaven.java:105)
    at org.apache.maven.cli.MavenCli.execute (MavenCli.java:956)
    at org.apache.maven.cli.MavenCli.doMain (MavenCli.java:288)
    at org.apache.maven.cli.MavenCli.main (MavenCli.java:192)
    at jdk.internal.reflect.NativeMethodAccessorImpl.invoke0 (Native Method)
    at jdk.internal.reflect.NativeMethodAccessorImpl.invoke (NativeMethodAccessorImpl.java:62)
    at jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke (DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke (Method.java:566)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced (Launcher.java:282)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launch (Launcher.java:225)
    at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode (Launcher.java:406)
    at org.codehaus.plexus.classworlds.launcher.Launcher.main (Launcher.java:347)
Caused by: java.lang.IllegalStateException: Could not find NuGet package! ModuleDir=C:\Users\m86194\git\microsvc-operational-information\Operational_Information, PackageDir=C:\Users\m86194\git\microsvc-operational-information\Operational_Information\bin, PackOutput=bin
    at org.eobjects.build.PluginHelper.getNugetPackage (PluginHelper.java:92)
    at org.eobjects.build.DotnetNugetAddMojo.execute (DotnetNugetAddMojo.java:39)
    at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo (DefaultBuildPluginManager.java:137)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:210)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:156)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:148)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:117)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:81)
    at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build (SingleThreadedBuilder.java:56)
    at org.apache.maven.lifecycle.internal.LifecycleStarter.execute (LifecycleStarter.java:128)
    at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:305)
    at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:192)
    at org.apache.maven.DefaultMaven.execute (DefaultMaven.java:105)
    at org.apache.maven.cli.MavenCli.execute (MavenCli.java:956)
    at org.apache.maven.cli.MavenCli.doMain (MavenCli.java:288)
    at org.apache.maven.cli.MavenCli.main (MavenCli.java:192)
    at jdk.internal.reflect.NativeMethodAccessorImpl.invoke0 (Native Method)
    at jdk.internal.reflect.NativeMethodAccessorImpl.invoke (NativeMethodAccessorImpl.java:62)
    at jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke (DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke (Method.java:566)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced (Launcher.java:282)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launch (Launcher.java:225)
    at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode (Launcher.java:406)
    at org.codehaus.plexus.classworlds.launcher.Launcher.main (Launcher.java:347)

I cannot get a successful build from my very simple .net assembly

[INFO]
[INFO] --- dotnet-maven-plugin:0.24:restore (default-restore) @ activeDirectoryDotNetCoreLib --- [INFO] ------------------------------------------------------------------------ [INFO] Reactor Summary for CommonModules Integrated Security 0.0.2-SNAPSHOT: [INFO] [INFO] CommonModules Integrated Security .................. SUCCESS [ 0.012 s] [INFO] CommonModules Integrated Security Go Executable .... SUCCESS [ 6.560 s] [INFO] CommonModules Integrated Security Dynamic Library .. SUCCESS [ 7.807 s] [INFO] CommonModules Integrated Security DotNetCore Lib ... FAILURE [ 0.019 s] [INFO] ------------------------------------------------------------------------ [INFO] BUILD FAILURE [INFO] ------------------------------------------------------------------------ [INFO] Total time: 20.876 s [INFO] Finished at: 2019-07-17T16:31:43-06:00 [INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.eobjects.build:dotnet-maven-plugin:0.24:restore (default-restore) on project activeDirectoryDotNetCoreLib: Could not find any directories with a project/build file. -> [Help 1] [ERROR] [ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch. [ERROR] Re-run Maven using the -X switch to enable full debug logging. [ERROR] [ERROR] For more information about the errors and possible solutions, please read the following articles: [ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoFailureException [ERROR] [ERROR] After correcting the problems, you can resume the build with the command [ERROR] mvn -rf :activeDirectoryDotNetCoreLib

Here is my pom.xml ....be gentle I just heard of maven about 2 weeks ago....

CommonModules Integrated Security DotNetCore Lib
Build and deploy

 <version>0.0.2-SNAPSHOT</version>
 <packaging>dotnet</packaging>
 <modelVersion>4.0.0</modelVersion>

 <parent>
      <groupId>com.beckman.particle.commonmodules</groupId>
      <artifactId>integrated-security</artifactId>
      <version>0.0.2-SNAPSHOT</version>
 </parent>

 <artifactId>activeDirectoryDotNetCoreLib</artifactId>
 
 <properties>
      <target.name>activeDirectoryGroupsDotNet${dynamicLib.extension}</target.name>
      <rootPOM>${basedir}${file.separator}..${file.separator}</rootPOM>
 </properties>

 <build>
      <sourceDirectory>${rootPOM}${file.separator}src${file.separator}main${file.separator}csharp</sourceDirectory>
      <directory>${rootPOM}${file.separator}bin</directory>
      <defaultGoal>Clean restore package</defaultGoal>
      <finalName>${target.name}${final.extension}</finalName>
      <plugins>
           <plugin>
                <groupId>org.eobjects.build</groupId>
                <artifactId>dotnet-maven-plugin</artifactId>
                <version>0.24</version>
                <extensions>true</extensions>
                <configuration>
                     <buildConfiguration>Release</buildConfiguration>
                     <buildEnabled>true</buildEnabled>
                     <cleanEnabled>true</cleanEnabled>
                </configuration>
           </plugin>
           <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-release-plugin</artifactId>
                <configuration>
                     <preparationGoals>dotnet:update-versions</preparationGoals>
                </configuration>
           </plugin>
      </plugins>
 </build>

Support the new .csproj project/build file

With the latest .NET Core SDK it seems project.json is no longer the standard build file, but rather [projectname].csproj

  • Detect projects with .csproj file.
  • Support version updates in .csproj files
  • Support dependency updates in .csproj files

[Question/Issue?] The target "pack" does not exist in the project

Hello,

I made some progress, I am able to generate the dll file
However, I am getting "The target "pack" does not exist in the project."

I am not familiar with the .net environment, I looked online:
one of the solutions suggests adding the import project and creating a .sln file as well here.
I tried it as well but didn't work.

I attached my saref.csproj

any ideas?
Thank you for your help,

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.